mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
TextArea: update background color property if enabled or editable state changes in the same way as Swing does it for all other text components (issue #147)
This commit is contained in:
@@ -11,6 +11,9 @@ FlatLaf Change Log
|
|||||||
#### Fixed bugs
|
#### Fixed bugs
|
||||||
|
|
||||||
- Button: "selected" state was not shown. (issue #161)
|
- Button: "selected" state was not shown. (issue #161)
|
||||||
|
- TextArea: Update background color property if enabled or editable state
|
||||||
|
changes in the same way as Swing does it for all other text components. (issue
|
||||||
|
#147)
|
||||||
|
|
||||||
#### Other Changes
|
#### Other Changes
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class FlatTextAreaUI
|
|||||||
{
|
{
|
||||||
protected int minimumWidth;
|
protected int minimumWidth;
|
||||||
protected boolean isIntelliJTheme;
|
protected boolean isIntelliJTheme;
|
||||||
|
protected Color background;
|
||||||
protected Color disabledBackground;
|
protected Color disabledBackground;
|
||||||
protected Color inactiveBackground;
|
protected Color inactiveBackground;
|
||||||
|
|
||||||
@@ -67,12 +68,20 @@ public class FlatTextAreaUI
|
|||||||
return new FlatTextAreaUI();
|
return new FlatTextAreaUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installUI( JComponent c ) {
|
||||||
|
super.installUI( c );
|
||||||
|
|
||||||
|
updateBackground();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
|
||||||
|
background = UIManager.getColor( "TextArea.background" );
|
||||||
disabledBackground = UIManager.getColor( "TextArea.disabledBackground" );
|
disabledBackground = UIManager.getColor( "TextArea.disabledBackground" );
|
||||||
inactiveBackground = UIManager.getColor( "TextArea.inactiveBackground" );
|
inactiveBackground = UIManager.getColor( "TextArea.inactiveBackground" );
|
||||||
}
|
}
|
||||||
@@ -81,6 +90,7 @@ public class FlatTextAreaUI
|
|||||||
protected void uninstallDefaults() {
|
protected void uninstallDefaults() {
|
||||||
super.uninstallDefaults();
|
super.uninstallDefaults();
|
||||||
|
|
||||||
|
background = null;
|
||||||
disabledBackground = null;
|
disabledBackground = null;
|
||||||
inactiveBackground = null;
|
inactiveBackground = null;
|
||||||
}
|
}
|
||||||
@@ -89,26 +99,36 @@ public class FlatTextAreaUI
|
|||||||
protected void propertyChange( PropertyChangeEvent e ) {
|
protected void propertyChange( PropertyChangeEvent e ) {
|
||||||
super.propertyChange( e );
|
super.propertyChange( e );
|
||||||
FlatEditorPaneUI.propertyChange( getComponent(), e );
|
FlatEditorPaneUI.propertyChange( getComponent(), e );
|
||||||
|
|
||||||
|
switch( e.getPropertyName() ) {
|
||||||
|
case "editable":
|
||||||
|
case "enabled":
|
||||||
|
updateBackground();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void updateBackground() {
|
||||||
protected void paintSafely( Graphics g ) {
|
|
||||||
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void paintBackground( Graphics g ) {
|
|
||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
|
|
||||||
Color background = c.getBackground();
|
Color background = c.getBackground();
|
||||||
g.setColor( !(background instanceof UIResource)
|
if( !(background instanceof UIResource) )
|
||||||
? background
|
return;
|
||||||
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
|
|
||||||
? FlatUIUtils.getParentBackground( c )
|
// do not update background if it currently has a unknown color (assigned from outside)
|
||||||
: (!c.isEnabled()
|
if( background != this.background &&
|
||||||
? disabledBackground
|
background != disabledBackground &&
|
||||||
: (!c.isEditable() ? inactiveBackground : background))) );
|
background != inactiveBackground )
|
||||||
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
return;
|
||||||
|
|
||||||
|
Color newBackground = !c.isEnabled()
|
||||||
|
? disabledBackground
|
||||||
|
: (!c.isEditable()
|
||||||
|
? inactiveBackground
|
||||||
|
: this.background);
|
||||||
|
|
||||||
|
if( newBackground != background )
|
||||||
|
c.setBackground( newBackground );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,4 +148,22 @@ public class FlatTextAreaUI
|
|||||||
|
|
||||||
return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth );
|
return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintSafely( Graphics g ) {
|
||||||
|
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintBackground( Graphics g ) {
|
||||||
|
JTextComponent c = getComponent();
|
||||||
|
|
||||||
|
// for compatibility with IntelliJ themes
|
||||||
|
if( isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) && (c.getBackground() instanceof UIResource) ) {
|
||||||
|
FlatUIUtils.paintParentBackground( g, c );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.paintBackground( g );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ public class FlatComponentsTest
|
|||||||
JLabel labelLabel = new JLabel();
|
JLabel labelLabel = new JLabel();
|
||||||
JLabel label1 = new JLabel();
|
JLabel label1 = new JLabel();
|
||||||
JLabel label2 = new JLabel();
|
JLabel label2 = new JLabel();
|
||||||
|
FlatComponentsTest.TestMultiLineLabel testMultiLineLabel1 = new FlatComponentsTest.TestMultiLineLabel();
|
||||||
JLabel buttonLabel = new JLabel();
|
JLabel buttonLabel = new JLabel();
|
||||||
JButton button1 = new JButton();
|
JButton button1 = new JButton();
|
||||||
JButton button17 = new JButton();
|
JButton button17 = new JButton();
|
||||||
@@ -367,6 +368,10 @@ public class FlatComponentsTest
|
|||||||
label2.setEnabled(false);
|
label2.setEnabled(false);
|
||||||
add(label2, "cell 2 0");
|
add(label2, "cell 2 0");
|
||||||
|
|
||||||
|
//---- testMultiLineLabel1 ----
|
||||||
|
testMultiLineLabel1.setText("Multi-line label based on JTextArea\n2nd line");
|
||||||
|
add(testMultiLineLabel1, "cell 3 0 2 1");
|
||||||
|
|
||||||
//---- buttonLabel ----
|
//---- buttonLabel ----
|
||||||
buttonLabel.setText("JButton:");
|
buttonLabel.setText("JButton:");
|
||||||
add(buttonLabel, "cell 0 1");
|
add(buttonLabel, "cell 0 1");
|
||||||
@@ -1402,4 +1407,24 @@ public class FlatComponentsTest
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class TestMultiLineLabel -------------------------------------------
|
||||||
|
|
||||||
|
private static class TestMultiLineLabel
|
||||||
|
extends JTextArea
|
||||||
|
{
|
||||||
|
public TestMultiLineLabel() {
|
||||||
|
setEditable( false );
|
||||||
|
setFocusable( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateUI() {
|
||||||
|
super.updateUI();
|
||||||
|
setBackground( UIManager.getColor( "Label.background" ) );
|
||||||
|
setForeground( UIManager.getColor( "Label.foreground" ) );
|
||||||
|
setFont( UIManager.getFont( "Label.font" ) );
|
||||||
|
setBorder( null );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 2 0"
|
"value": "cell 2 0"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "com.formdev.flatlaf.testing.FlatComponentsTest$TestMultiLineLabel" ) {
|
||||||
|
name: "testMultiLineLabel1"
|
||||||
|
"text": "Multi-line label based on JTextArea\n2nd line"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 3 0 2 1"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "buttonLabel"
|
name: "buttonLabel"
|
||||||
"text": "JButton:"
|
"text": "JButton:"
|
||||||
|
|||||||
Reference in New Issue
Block a user