mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
PasswordField: support "reveal" button to show password (issue #173)
This commit is contained in:
@@ -126,6 +126,14 @@ public class FlatTextComponentsTest
|
||||
showClearButtonCheckBox.isSelected() );
|
||||
}
|
||||
|
||||
private void showRevealButton() {
|
||||
for( Component c : getComponents() ) {
|
||||
if( c instanceof JPasswordField )
|
||||
((JPasswordField)c).putClientProperty(FlatClientProperties.STYLE,
|
||||
showRevealButtonCheckBox.isSelected() ? "showRevealButton: true" : null );
|
||||
}
|
||||
}
|
||||
|
||||
private void putTextFieldClientProperty( String key, Object value ) {
|
||||
for( Component c : getComponents() ) {
|
||||
if( c instanceof JTextField )
|
||||
@@ -174,6 +182,7 @@ public class FlatTextComponentsTest
|
||||
leadingComponentVisibleCheckBox = new JCheckBox();
|
||||
trailingComponentVisibleCheckBox = new JCheckBox();
|
||||
showClearButtonCheckBox = new JCheckBox();
|
||||
showRevealButtonCheckBox = new JCheckBox();
|
||||
JLabel passwordFieldLabel = new JLabel();
|
||||
JPasswordField passwordField1 = new JPasswordField();
|
||||
JPasswordField passwordField3 = new JPasswordField();
|
||||
@@ -326,6 +335,7 @@ public class FlatTextComponentsTest
|
||||
"[]" +
|
||||
"[]0" +
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[]"));
|
||||
|
||||
//---- button1 ----
|
||||
@@ -417,6 +427,12 @@ public class FlatTextComponentsTest
|
||||
showClearButtonCheckBox.setName("showClearButtonCheckBox");
|
||||
showClearButtonCheckBox.addActionListener(e -> showClearButton());
|
||||
panel1.add(showClearButtonCheckBox, "cell 0 11 2 1,alignx left,growx 0");
|
||||
|
||||
//---- showRevealButtonCheckBox ----
|
||||
showRevealButtonCheckBox.setText("password reveal button");
|
||||
showRevealButtonCheckBox.setName("showRevealButtonCheckBox");
|
||||
showRevealButtonCheckBox.addActionListener(e -> showRevealButton());
|
||||
panel1.add(showRevealButtonCheckBox, "cell 0 12 2 1,alignx left,growx 0");
|
||||
}
|
||||
add(panel1, "cell 4 0 1 10,aligny top,growy 0");
|
||||
|
||||
@@ -733,6 +749,7 @@ public class FlatTextComponentsTest
|
||||
private JCheckBox leadingComponentVisibleCheckBox;
|
||||
private JCheckBox trailingComponentVisibleCheckBox;
|
||||
private JCheckBox showClearButtonCheckBox;
|
||||
private JCheckBox showRevealButtonCheckBox;
|
||||
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[][]0[][]"
|
||||
"$rowConstraints": "[][][][][][]0[][]0[][]0[][][]"
|
||||
} ) {
|
||||
name: "panel1"
|
||||
"border": new javax.swing.border.TitledBorder( "Control" )
|
||||
@@ -220,6 +220,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 11 2 1,alignx left,growx 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "showRevealButtonCheckBox"
|
||||
"text": "password reveal button"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showRevealButton", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 12 2 1,alignx left,growx 0"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 4 0 1 10,aligny top,growy 0"
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user