ComboBox: fixed vertical alignment of text in popup list with text in combo box in IntelliJ/Darcula themes

This commit is contained in:
Karl Tauber
2022-06-04 20:15:31 +02:00
parent 6c18431a30
commit 73b6ca3762
2 changed files with 15 additions and 4 deletions

View File

@@ -5,6 +5,8 @@ FlatLaf Change Log
#### Fixed bugs #### Fixed bugs
- ComboBox: Fixed vertical alignment of text in popup list with text in combo
box in IntelliJ/Darcula themes.
- TableHeader: Fixed exception when changing table structure (e.g. removing - TableHeader: Fixed exception when changing table structure (e.g. removing
column) from a table header popup menu action. (issue #532) column) from a table header popup menu action. (issue #532)

View File

@@ -608,7 +608,7 @@ public class FlatComboBoxUI
boolean shouldValidate = (c instanceof JPanel); boolean shouldValidate = (c instanceof JPanel);
paddingBorder.install( c ); paddingBorder.install( c, 0 );
currentValuePane.paintComponent( g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, shouldValidate ); currentValuePane.paintComponent( g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, shouldValidate );
paddingBorder.uninstall(); paddingBorder.uninstall();
@@ -682,7 +682,7 @@ public class FlatComboBoxUI
@Override @Override
protected Dimension getSizeForComponent( Component comp ) { protected Dimension getSizeForComponent( Component comp ) {
paddingBorder.install( comp ); paddingBorder.install( comp, 0 );
Dimension size = super.getSizeForComponent( comp ); Dimension size = super.getSizeForComponent( comp );
paddingBorder.uninstall(); paddingBorder.uninstall();
return size; return size;
@@ -900,7 +900,7 @@ public class FlatComboBoxUI
Component c = renderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); Component c = renderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
c.applyComponentOrientation( comboBox.getComponentOrientation() ); c.applyComponentOrientation( comboBox.getComponentOrientation() );
paddingBorder.install( c ); paddingBorder.install( c, Math.round( FlatUIUtils.getBorderFocusWidth( comboBox ) ) );
return c; return c;
} }
@@ -923,6 +923,7 @@ public class FlatComboBoxUI
private Insets padding; private Insets padding;
private JComponent rendererComponent; private JComponent rendererComponent;
private Border rendererBorder; private Border rendererBorder;
private int focusWidth;
CellPaddingBorder( Insets padding ) { CellPaddingBorder( Insets padding ) {
this.padding = padding; this.padding = padding;
@@ -930,10 +931,12 @@ public class FlatComboBoxUI
// using synchronized to avoid problems with code that modifies combo box // using synchronized to avoid problems with code that modifies combo box
// (model, selection, etc) not on AWT thread (which should be not done) // (model, selection, etc) not on AWT thread (which should be not done)
synchronized void install( Component c ) { synchronized void install( Component c, int focusWidth ) {
if( !(c instanceof JComponent) ) if( !(c instanceof JComponent) )
return; return;
this.focusWidth = focusWidth;
JComponent jc = (JComponent) c; JComponent jc = (JComponent) c;
Border oldBorder = jc.getBorder(); Border oldBorder = jc.getBorder();
if( oldBorder == this ) if( oldBorder == this )
@@ -987,6 +990,12 @@ public class FlatComboBoxUI
insets.bottom = padding.bottom; insets.bottom = padding.bottom;
insets.right = padding.right; insets.right = padding.right;
} }
// if used in popup list, add focus width for exact vertical alignment
// of text in popup list with text in combobox
insets.left += focusWidth;
insets.right += focusWidth;
return insets; return insets;
} }