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