TextField: fixed inactive and disabled background

This commit is contained in:
Karl Tauber
2019-08-21 14:07:38 +02:00
parent fdbcb52629
commit d0a7ded92b
5 changed files with 17 additions and 13 deletions

View File

@@ -93,6 +93,16 @@ public abstract class FlatLaf
public UIDefaults getDefaults() {
UIDefaults defaults = getBase().getDefaults();
// initialize some defaults (for overriding) that are used in basic UI delegates,
// but are not set in MetalLookAndFeel or BasicLookAndFeel
Color control = defaults.getColor( "control" );
defaults.put( "EditorPane.disabledBackground", control );
defaults.put( "FormattedTextField.disabledBackground", control );
defaults.put( "PasswordField.disabledBackground", control );
defaults.put( "TextArea.disabledBackground", control );
defaults.put( "TextField.disabledBackground", control );
defaults.put( "TextPane.disabledBackground", control );
initFonts( defaults );
loadDefaultsFromProperties( defaults );

View File

@@ -16,13 +16,11 @@
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTextFieldUI;
import javax.swing.text.JTextComponent;
@@ -67,19 +65,13 @@ public class FlatTextFieldUI
float focusWidth = FlatUIUtils.getFocusWidth();
g2.setColor( getBackground( c ) );
g2.setColor( c.getBackground() );
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, 0 );
} finally {
g2.dispose();
}
}
private Color getBackground( JTextComponent c ) {
return c.isEditable() && c.isEnabled()
? c.getBackground()
: UIManager.getColor( "TextField.disabledBackground" );
}
//---- class Handler ------------------------------------------------------
private class Handler

View File

@@ -32,6 +32,7 @@
*.inactiveForeground=@foreground
*.selectionBackground=4B6EAF
*.selectionForeground=@foreground
*.disabledBackground=@background
*.disabledText=@disabledText
@@ -92,4 +93,3 @@ Label.disabledForeground=@disabledText
#---- TextField ----
TextField.background=45494A
TextField.disabledBackground=@background

View File

@@ -28,10 +28,11 @@
*.textBackground=cccccc
*.textForeground=@foreground
*.caretForeground=@foreground
*.inactiveBackground=ffffff
*.inactiveBackground=@background
*.inactiveForeground=777777
*.selectionBackground=4A6EB7
*.selectionForeground=ffffff
*.disabledBackground=@background
*.disabledText=@disabledText
@@ -92,4 +93,3 @@ Label.disabledForeground=@disabledText
#---- TextField ----
TextField.background=ffffff
TextField.disabledBackground=@background

View File

@@ -18,7 +18,10 @@
*.background=ccffcc
*.foreground=ff0000
*.inactiveBackground=f0f0f0
*.disabledBackground=e0e0e0
*.disabledText=000088
*.inactiveForeground=000088
#---- Button ----
@@ -72,4 +75,3 @@ Label.disabledForeground=000088
#---- TextField ----
TextField.background=ffffff
TextField.disabledBackground=f2f2f2