mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 06:50:56 +03:00
ComboBox: fixed width of popup, which was too small if popup is wider than combo box and vertical scroll bar is visible (issue #137)
This commit is contained in:
@@ -15,6 +15,8 @@ FlatLaf Change Log
|
|||||||
- ToolTip: Do not show empty tooltip component if tooltip text is an empty
|
- ToolTip: Do not show empty tooltip component if tooltip text is an empty
|
||||||
string. (issue #134)
|
string. (issue #134)
|
||||||
- Button: Support specifying button border width.
|
- 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: Changed maximum row count of popup list to 15 (was 20). Set UI value
|
||||||
`ComboBox.maximumRowCount` to any integer to use a different value.
|
`ComboBox.maximumRowCount` to any integer to use a different value.
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import javax.swing.JComboBox;
|
|||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollBar;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.ListCellRenderer;
|
import javax.swing.ListCellRenderer;
|
||||||
@@ -544,13 +545,26 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rectangle computePopupBounds( int px, int py, int pw, int ph ) {
|
protected Rectangle computePopupBounds( int px, int py, int pw, int ph ) {
|
||||||
// get maximum display size of all items
|
// get maximum display width of all items
|
||||||
Dimension displaySize = getDisplaySize();
|
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
|
// make popup wider if necessary
|
||||||
if( displaySize.width > pw ) {
|
if( displayWidth > pw ) {
|
||||||
int diff = displaySize.width - pw;
|
int diff = displayWidth - pw;
|
||||||
pw = displaySize.width;
|
pw = displayWidth;
|
||||||
|
|
||||||
if( !comboBox.getComponentOrientation().isLeftToRight() )
|
if( !comboBox.getComponentOrientation().isLeftToRight() )
|
||||||
px -= diff;
|
px -= diff;
|
||||||
|
|||||||
Reference in New Issue
Block a user