mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Demo: added text field leading/trailing components example
This commit is contained in:
@@ -80,6 +80,7 @@ public class FlatTextComponentsTest
|
||||
JLabel l = new JLabel( "lead" );
|
||||
l.setOpaque( true );
|
||||
l.setBackground( Color.green );
|
||||
l.setVisible( leadingComponentVisibleCheckBox.isSelected() );
|
||||
return l;
|
||||
} );
|
||||
}
|
||||
@@ -92,10 +93,34 @@ public class FlatTextComponentsTest
|
||||
JLabel l = new JLabel( "tr" );
|
||||
l.setOpaque( true );
|
||||
l.setBackground( Color.magenta );
|
||||
l.setVisible( trailingComponentVisibleCheckBox.isSelected() );
|
||||
return l;
|
||||
} );
|
||||
}
|
||||
|
||||
private void leadingComponentVisible() {
|
||||
setLeadingTrailingComponentVisible( FlatClientProperties.TEXT_FIELD_LEADING_COMPONENT,
|
||||
leadingComponentVisibleCheckBox.isSelected() );
|
||||
}
|
||||
|
||||
private void trailingComponentVisible() {
|
||||
setLeadingTrailingComponentVisible( FlatClientProperties.TEXT_FIELD_TRAILING_COMPONENT,
|
||||
trailingComponentVisibleCheckBox.isSelected() );
|
||||
}
|
||||
|
||||
private void setLeadingTrailingComponentVisible( String key, boolean visible ) {
|
||||
for( Component c : getComponents() ) {
|
||||
if( c instanceof JTextField ) {
|
||||
Object value = ((JTextField)c).getClientProperty( key );
|
||||
if( value instanceof JComponent ) {
|
||||
((JComponent)value).setVisible( visible );
|
||||
c.revalidate();
|
||||
c.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void putTextFieldClientProperty( String key, Object value ) {
|
||||
for( Component c : getComponents() ) {
|
||||
if( c instanceof JTextField )
|
||||
@@ -141,6 +166,8 @@ public class FlatTextComponentsTest
|
||||
trailingIconCheckBox = new JCheckBox();
|
||||
leadingComponentCheckBox = new JCheckBox();
|
||||
trailingComponentCheckBox = new JCheckBox();
|
||||
leadingComponentVisibleCheckBox = new JCheckBox();
|
||||
trailingComponentVisibleCheckBox = new JCheckBox();
|
||||
JLabel passwordFieldLabel = new JLabel();
|
||||
JPasswordField passwordField1 = new JPasswordField();
|
||||
JPasswordField passwordField3 = new JPasswordField();
|
||||
@@ -290,6 +317,8 @@ public class FlatTextComponentsTest
|
||||
"[]0" +
|
||||
"[]" +
|
||||
"[]0" +
|
||||
"[]" +
|
||||
"[]0" +
|
||||
"[]"));
|
||||
|
||||
//---- button1 ----
|
||||
@@ -361,8 +390,22 @@ public class FlatTextComponentsTest
|
||||
trailingComponentCheckBox.setName("trailingComponentCheckBox");
|
||||
trailingComponentCheckBox.addActionListener(e -> trailingComponent());
|
||||
panel1.add(trailingComponentCheckBox, "cell 0 8 2 1,alignx left,growx 0");
|
||||
|
||||
//---- leadingComponentVisibleCheckBox ----
|
||||
leadingComponentVisibleCheckBox.setText("leading component visible");
|
||||
leadingComponentVisibleCheckBox.setSelected(true);
|
||||
leadingComponentVisibleCheckBox.setName("leadingComponentVisibleCheckBox");
|
||||
leadingComponentVisibleCheckBox.addActionListener(e -> leadingComponentVisible());
|
||||
panel1.add(leadingComponentVisibleCheckBox, "cell 0 9 2 1,alignx left,growx 0");
|
||||
|
||||
//---- trailingComponentVisibleCheckBox ----
|
||||
trailingComponentVisibleCheckBox.setText("trailing component visible");
|
||||
trailingComponentVisibleCheckBox.setSelected(true);
|
||||
trailingComponentVisibleCheckBox.setName("trailingComponentVisibleCheckBox");
|
||||
trailingComponentVisibleCheckBox.addActionListener(e -> trailingComponentVisible());
|
||||
panel1.add(trailingComponentVisibleCheckBox, "cell 0 10 2 1,alignx left,growx 0");
|
||||
}
|
||||
add(panel1, "cell 4 0 1 6,aligny top,growy 0");
|
||||
add(panel1, "cell 4 0 1 10,aligny top,growy 0");
|
||||
|
||||
//---- passwordFieldLabel ----
|
||||
passwordFieldLabel.setText("JPasswordField:");
|
||||
@@ -674,6 +717,8 @@ public class FlatTextComponentsTest
|
||||
private JCheckBox trailingIconCheckBox;
|
||||
private JCheckBox leadingComponentCheckBox;
|
||||
private JCheckBox trailingComponentCheckBox;
|
||||
private JCheckBox leadingComponentVisibleCheckBox;
|
||||
private JCheckBox trailingComponentVisibleCheckBox;
|
||||
private JTextField textField;
|
||||
private JCheckBox dragEnabledCheckBox;
|
||||
private JTextArea textArea;
|
||||
|
||||
@@ -77,7 +77,7 @@ new FormModel {
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "hidemode 3"
|
||||
"$columnConstraints": "[fill][fill]"
|
||||
"$rowConstraints": "[][][][][][]0[][]0[]"
|
||||
"$rowConstraints": "[][][][][][]0[][]0[][]0[]"
|
||||
} ) {
|
||||
name: "panel1"
|
||||
"border": new javax.swing.border.TitledBorder( "Control" )
|
||||
@@ -188,8 +188,30 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 8 2 1,alignx left,growx 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "leadingComponentVisibleCheckBox"
|
||||
"text": "leading component visible"
|
||||
"selected": true
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "leadingComponentVisible", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 9 2 1,alignx left,growx 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "trailingComponentVisibleCheckBox"
|
||||
"text": "trailing component visible"
|
||||
"selected": true
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "trailingComponentVisible", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 10 2 1,alignx left,growx 0"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 4 0 1 6,aligny top,growy 0"
|
||||
"value": "cell 4 0 1 10,aligny top,growy 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "passwordFieldLabel"
|
||||
|
||||
Reference in New Issue
Block a user