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:
Karl Tauber
2020-08-25 19:15:53 +02:00
parent e55b2afd60
commit a1dab94a61
4 changed files with 87 additions and 15 deletions

View File

@@ -134,6 +134,7 @@ public class FlatComponentsTest
JLabel labelLabel = new JLabel();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
FlatComponentsTest.TestMultiLineLabel testMultiLineLabel1 = new FlatComponentsTest.TestMultiLineLabel();
JLabel buttonLabel = new JLabel();
JButton button1 = new JButton();
JButton button17 = new JButton();
@@ -367,6 +368,10 @@ public class FlatComponentsTest
label2.setEnabled(false);
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.setText("JButton:");
add(buttonLabel, "cell 0 1");
@@ -1402,4 +1407,24 @@ public class FlatComponentsTest
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 );
}
}
}

View File

@@ -33,6 +33,12 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"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" ) {
name: "buttonLabel"
"text": "JButton:"