Skip to content

Commit

Permalink
ComboBox: fixed width of popup, which was too small if popup is wider…
Browse files Browse the repository at this point in the history
… than combo box and vertical scroll bar is visible (issue #137)
  • Loading branch information
DevCharly committed Jul 30, 2020
1 parent 2640ab2 commit 5ebdf64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ FlatLaf Change Log
- ToolTip: Do not show empty tooltip component if tooltip text is an empty
string. (issue #134)
- Button: Support specifying button border width.
- ComboBox: Fixed width of popup, which was too small if popup is wider than
combo box and vertical scroll bar is visible. (issue #137)
- ComboBox: Changed maximum row count of popup list to 15 (was 20). Set UI value
`ComboBox.maximumRowCount` to any integer to use a different value.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer;
Expand Down Expand Up @@ -544,13 +545,26 @@ protected FlatComboPopup( JComboBox combo ) {

@Override
protected Rectangle computePopupBounds( int px, int py, int pw, int ph ) {
// get maximum display size of all items
Dimension displaySize = getDisplaySize();
// get maximum display width of all items
int displayWidth = getDisplaySize().width;

// add border insets
for( Border border : new Border[] { scroller.getViewportBorder(), scroller.getBorder() } ) {
if( border != null ) {
Insets borderInsets = border.getBorderInsets( null );
displayWidth += borderInsets.left + borderInsets.right;
}
}

// add width of vertical scroll bar
JScrollBar verticalScrollBar = scroller.getVerticalScrollBar();
if( verticalScrollBar != null )
displayWidth += verticalScrollBar.getPreferredSize().width;

// make popup wider if necessary
if( displaySize.width > pw ) {
int diff = displaySize.width - pw;
pw = displaySize.width;
if( displayWidth > pw ) {
int diff = displayWidth - pw;
pw = displayWidth;

if( !comboBox.getComponentOrientation().isLeftToRight() )
px -= diff;
Expand Down

0 comments on commit 5ebdf64

Please sign in to comment.