mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
ComboBox and Spinner:
- make child components explicitly non-opaque - paint parent background only if necessary
This commit is contained in:
@@ -212,7 +212,7 @@ public class FlatComboBoxUI
|
||||
String propertyName = e.getPropertyName();
|
||||
|
||||
if( editor != null &&
|
||||
((source == comboBox && (propertyName == "background" || propertyName == "foreground")) ||
|
||||
((source == comboBox && propertyName == "foreground") ||
|
||||
(source == editor && propertyName == "enabled")) )
|
||||
{
|
||||
// fix editor component colors
|
||||
@@ -242,6 +242,10 @@ public class FlatComboBoxUI
|
||||
if( editor instanceof JTextComponent )
|
||||
((JTextComponent)editor).setBorder( BorderFactory.createEmptyBorder() );
|
||||
|
||||
// explicitly make non-opaque
|
||||
if( editor instanceof JComponent )
|
||||
((JComponent)editor).setOpaque( false );
|
||||
|
||||
editor.applyComponentOrientation( comboBox.getComponentOrientation() );
|
||||
|
||||
updateEditorColors();
|
||||
@@ -252,7 +256,6 @@ public class FlatComboBoxUI
|
||||
// is used, then the editor is updated after the combobox and the
|
||||
// colors are again replaced with default colors
|
||||
boolean enabled = editor.isEnabled();
|
||||
editor.setBackground( FlatUIUtils.nonUIResource( enabled ? comboBox.getBackground() : disabledBackground ) );
|
||||
editor.setForeground( FlatUIUtils.nonUIResource( (enabled || editor instanceof JTextComponent)
|
||||
? comboBox.getForeground()
|
||||
: disabledForeground ) );
|
||||
@@ -275,7 +278,7 @@ public class FlatComboBoxUI
|
||||
@Override
|
||||
public void update( Graphics g, JComponent c ) {
|
||||
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||
if( c.isOpaque() )
|
||||
if( c.isOpaque() && (focusWidth > 0 || arc != 0) )
|
||||
FlatUIUtils.paintParentBackground( g, c );
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
@@ -155,6 +155,13 @@ public class FlatSpinnerUI
|
||||
@Override
|
||||
protected JComponent createEditor() {
|
||||
JComponent editor = super.createEditor();
|
||||
|
||||
// explicitly make non-opaque
|
||||
editor.setOpaque( false );
|
||||
JTextField textField = getEditorTextField( editor );
|
||||
if( textField != null )
|
||||
textField.setOpaque( false );
|
||||
|
||||
updateEditorColors();
|
||||
return editor;
|
||||
}
|
||||
@@ -186,8 +193,6 @@ public class FlatSpinnerUI
|
||||
// use non-UIResource colors because when SwingUtilities.updateComponentTreeUI()
|
||||
// is used, then the text field is updated after the spinner and the
|
||||
// colors are again replaced with default colors
|
||||
textField.setBackground( FlatUIUtils.nonUIResource( spinner.isEnabled()
|
||||
? spinner.getBackground() : disabledBackground ) );
|
||||
textField.setForeground( FlatUIUtils.nonUIResource( spinner.getForeground() ) );
|
||||
textField.setDisabledTextColor( FlatUIUtils.nonUIResource( disabledForeground ) );
|
||||
}
|
||||
@@ -229,7 +234,7 @@ public class FlatSpinnerUI
|
||||
@Override
|
||||
public void update( Graphics g, JComponent c ) {
|
||||
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||
if( c.isOpaque() )
|
||||
if( c.isOpaque() && (focusWidth > 0 || arc != 0) )
|
||||
FlatUIUtils.paintParentBackground( g, c );
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
@@ -373,7 +378,6 @@ public class FlatSpinnerUI
|
||||
@Override
|
||||
public void propertyChange( PropertyChangeEvent e ) {
|
||||
switch( e.getPropertyName() ) {
|
||||
case "background":
|
||||
case "foreground":
|
||||
case "enabled":
|
||||
updateEditorColors();
|
||||
|
||||
Reference in New Issue
Block a user