support different component border colors to indicate errors, warnings or custom state (set client property JComponent.outline to error, warning or any java.awt.Color)

This commit is contained in:
Karl Tauber
2020-05-17 13:43:19 +02:00
parent ff545e6ecd
commit 800dbf3ba9
15 changed files with 339 additions and 7 deletions

View File

@@ -84,6 +84,26 @@ public class FlatComponentsTest
}
}
private void outlineChanged() {
FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this );
if( frame == null )
return;
Object outline = errorOutlineRadioButton.isSelected() ? "error"
: warningOutlineRadioButton.isSelected() ? "warning"
: magentaOutlineRadioButton.isSelected() ? Color.magenta
: magentaCyanOutlineRadioButton.isSelected() ? new Color[] { Color.magenta, Color.cyan }
: null;
frame.updateComponentsRecur( this, (c, type) -> {
if( c instanceof JComponent )
((JComponent)c).putClientProperty( FlatClientProperties.OUTLINE, outline );
} );
frame.repaint();
textField1.requestFocusInWindow();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JLabel labelLabel = new JLabel();
@@ -146,7 +166,7 @@ public class FlatComponentsTest
JComboBox<String> comboBox7 = new JComboBox<>();
JSpinner spinner3 = new JSpinner();
JLabel textFieldLabel = new JLabel();
JTextField textField1 = new JTextField();
textField1 = new JTextField();
JTextField textField2 = new JTextField();
JTextField textField3 = new JTextField();
JTextField textField4 = new JTextField();
@@ -215,6 +235,12 @@ public class FlatComponentsTest
JButton button10 = new JButton();
JButton button11 = new JButton();
JToggleButton toggleButton7 = new JToggleButton();
JPanel panel4 = new JPanel();
noOutlineRadioButton = new JRadioButton();
errorOutlineRadioButton = new JRadioButton();
warningOutlineRadioButton = new JRadioButton();
magentaOutlineRadioButton = new JRadioButton();
magentaCyanOutlineRadioButton = new JRadioButton();
JScrollPane scrollPane15 = new JScrollPane();
JPanel panel3 = new JPanel();
JButton button21 = new JButton();
@@ -1013,6 +1039,38 @@ public class FlatComponentsTest
}
add(toolBar2, "cell 4 13 1 6,growy");
//======== panel4 ========
{
panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
//---- noOutlineRadioButton ----
noOutlineRadioButton.setText("no outline");
noOutlineRadioButton.setSelected(true);
noOutlineRadioButton.addActionListener(e -> outlineChanged());
panel4.add(noOutlineRadioButton);
//---- errorOutlineRadioButton ----
errorOutlineRadioButton.setText("error");
errorOutlineRadioButton.addActionListener(e -> outlineChanged());
panel4.add(errorOutlineRadioButton);
//---- warningOutlineRadioButton ----
warningOutlineRadioButton.setText("warning");
warningOutlineRadioButton.addActionListener(e -> outlineChanged());
panel4.add(warningOutlineRadioButton);
//---- magentaOutlineRadioButton ----
magentaOutlineRadioButton.setText("magenta");
magentaOutlineRadioButton.addActionListener(e -> outlineChanged());
panel4.add(magentaOutlineRadioButton);
//---- magentaCyanOutlineRadioButton ----
magentaCyanOutlineRadioButton.setText("magenta / cyan");
magentaCyanOutlineRadioButton.addActionListener(e -> outlineChanged());
panel4.add(magentaCyanOutlineRadioButton);
}
add(panel4, "cell 5 13");
//======== scrollPane15 ========
{
scrollPane15.setBorder(BorderFactory.createEmptyBorder());
@@ -1240,6 +1298,14 @@ public class FlatComponentsTest
toolBar4.add(toggleButton26);
}
add(toolBar4, "cell 3 23 3 1");
//---- buttonGroup1 ----
ButtonGroup buttonGroup1 = new ButtonGroup();
buttonGroup1.add(noOutlineRadioButton);
buttonGroup1.add(errorOutlineRadioButton);
buttonGroup1.add(warningOutlineRadioButton);
buttonGroup1.add(magentaOutlineRadioButton);
buttonGroup1.add(magentaCyanOutlineRadioButton);
// JFormDesigner - End of component initialization //GEN-END:initComponents
// BasicComboBoxRenderer customRenderer = new BasicComboBoxRenderer();
@@ -1252,8 +1318,14 @@ public class FlatComponentsTest
private JComboBox<String> buttonTypeComboBox;
private JCheckBox contentAreaFilledCheckBox;
private JCheckBox roundRectCheckBox;
private JTextField textField1;
private JProgressBar progressBar3;
private JProgressBar progressBar4;
private JRadioButton noOutlineRadioButton;
private JRadioButton errorOutlineRadioButton;
private JRadioButton warningOutlineRadioButton;
private JRadioButton magentaOutlineRadioButton;
private JRadioButton magentaCyanOutlineRadioButton;
private JSlider slider3;
private JProgressBar progressBar1;
private JProgressBar progressBar2;

View File

@@ -514,6 +514,9 @@ new FormModel {
add( new FormComponent( "javax.swing.JTextField" ) {
name: "textField1"
"text": "editable"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 7,growx"
} )
@@ -955,6 +958,59 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 13 1 6,growy"
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class javax.swing.BoxLayout ) {
"axis": 1
} ) {
name: "panel4"
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "noOutlineRadioButton"
"text": "no outline"
"$buttonGroup": new FormReference( "buttonGroup1" )
"selected": true
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "outlineChanged", false ) )
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "errorOutlineRadioButton"
"text": "error"
"$buttonGroup": new FormReference( "buttonGroup1" )
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "outlineChanged", false ) )
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "warningOutlineRadioButton"
"text": "warning"
"$buttonGroup": new FormReference( "buttonGroup1" )
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "outlineChanged", false ) )
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "magentaOutlineRadioButton"
"text": "magenta"
"$buttonGroup": &FormReference0 new FormReference( "buttonGroup1" )
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "outlineChanged", false ) )
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "magentaCyanOutlineRadioButton"
"text": "magenta / cyan"
"$buttonGroup": #FormReference0
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "outlineChanged", false ) )
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 13"
} )
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "scrollPane15"
"border": new javax.swing.border.EmptyBorder( 0, 0, 0, 0 )
@@ -1247,5 +1303,10 @@ new FormModel {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 1135, 800 )
} )
add( new FormNonVisual( "javax.swing.ButtonGroup" ) {
name: "buttonGroup1"
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 810 )
} )
}
}

View File

@@ -440,7 +440,7 @@ public class FlatTestFrame
sizeVariantComboBox.setVisible( visible );
}
private void updateComponentsRecur( Container container, BiConsumer<Component, String> action ) {
void updateComponentsRecur( Container container, BiConsumer<Component, String> action ) {
for( Component c : container.getComponents() ) {
if( c instanceof JPanel || c instanceof JDesktopPane ) {
updateComponentsRecur( (Container) c, action );

View File

@@ -202,7 +202,10 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI
Component.arc 5
Component.arrowType chevron
Component.borderColor #646464 javax.swing.plaf.ColorUIResource [UI]
Component.custom.borderColor #bf4040 com.formdev.flatlaf.util.DerivedColor [UI] desaturate(50% relative)
Component.disabledBorderColor #646464 javax.swing.plaf.ColorUIResource [UI]
Component.error.borderColor #725555 javax.swing.plaf.ColorUIResource [UI]
Component.error.focusedBorderColor #8b3c3c javax.swing.plaf.ColorUIResource [UI]
Component.focusColor #3d6185 javax.swing.plaf.ColorUIResource [UI]
Component.focusWidth 0
Component.focusedBorderColor #466d94 javax.swing.plaf.ColorUIResource [UI]
@@ -211,6 +214,8 @@ Component.hideMnemonics true
Component.innerFocusWidth 0.5
Component.linkColor #589df6 javax.swing.plaf.ColorUIResource [UI]
Component.minimumWidth 64
Component.warning.borderColor #725627 javax.swing.plaf.ColorUIResource [UI]
Component.warning.focusedBorderColor #ac7920 javax.swing.plaf.ColorUIResource [UI]
#---- DatePicker ----

View File

@@ -201,7 +201,10 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI
Component.arc 5
Component.arrowType chevron
Component.borderColor #646464 javax.swing.plaf.ColorUIResource [UI]
Component.custom.borderColor #bf4040 com.formdev.flatlaf.util.DerivedColor [UI] desaturate(50% relative)
Component.disabledBorderColor #646464 javax.swing.plaf.ColorUIResource [UI]
Component.error.borderColor #725555 javax.swing.plaf.ColorUIResource [UI]
Component.error.focusedBorderColor #8b3c3c javax.swing.plaf.ColorUIResource [UI]
Component.focusColor #3d6185 javax.swing.plaf.ColorUIResource [UI]
Component.focusWidth 0
Component.focusedBorderColor #466d94 javax.swing.plaf.ColorUIResource [UI]
@@ -210,6 +213,8 @@ Component.hideMnemonics true
Component.innerFocusWidth 0.5
Component.linkColor #589df6 javax.swing.plaf.ColorUIResource [UI]
Component.minimumWidth 64
Component.warning.borderColor #725627 javax.swing.plaf.ColorUIResource [UI]
Component.warning.focusedBorderColor #ac7920 javax.swing.plaf.ColorUIResource [UI]
#---- DatePicker ----

View File

@@ -203,7 +203,10 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI
Component.arc 5
Component.arrowType chevron
Component.borderColor #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
Component.custom.borderColor #f38d8d com.formdev.flatlaf.util.DerivedColor [UI] desaturate(20%) lighten(25%)
Component.disabledBorderColor #cfcfcf javax.swing.plaf.ColorUIResource [UI]
Component.error.borderColor #ebb8bc javax.swing.plaf.ColorUIResource [UI]
Component.error.focusedBorderColor #e53e4d javax.swing.plaf.ColorUIResource [UI]
Component.focusColor #97c3f3 javax.swing.plaf.ColorUIResource [UI]
Component.focusWidth 0
Component.focusedBorderColor #87afda javax.swing.plaf.ColorUIResource [UI]
@@ -212,6 +215,8 @@ Component.hideMnemonics true
Component.innerFocusWidth 0.5
Component.linkColor #2470b3 javax.swing.plaf.ColorUIResource [UI]
Component.minimumWidth 64
Component.warning.borderColor #fed284 javax.swing.plaf.ColorUIResource [UI]
Component.warning.focusedBorderColor #e2a53a javax.swing.plaf.ColorUIResource [UI]
#---- DatePicker ----

View File

@@ -202,7 +202,10 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI
Component.arc 5
Component.arrowType chevron
Component.borderColor #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
Component.custom.borderColor #f38d8d com.formdev.flatlaf.util.DerivedColor [UI] desaturate(20%) lighten(25%)
Component.disabledBorderColor #cfcfcf javax.swing.plaf.ColorUIResource [UI]
Component.error.borderColor #ebb8bc javax.swing.plaf.ColorUIResource [UI]
Component.error.focusedBorderColor #e53e4d javax.swing.plaf.ColorUIResource [UI]
Component.focusColor #97c3f3 javax.swing.plaf.ColorUIResource [UI]
Component.focusWidth 0
Component.focusedBorderColor #87afda javax.swing.plaf.ColorUIResource [UI]
@@ -211,6 +214,8 @@ Component.hideMnemonics true
Component.innerFocusWidth 0.5
Component.linkColor #2470b3 javax.swing.plaf.ColorUIResource [UI]
Component.minimumWidth 64
Component.warning.borderColor #fed284 javax.swing.plaf.ColorUIResource [UI]
Component.warning.focusedBorderColor #e2a53a javax.swing.plaf.ColorUIResource [UI]
#---- DatePicker ----