TextComponent: support placeholder text that is displayed if text field is empty (set client property "JTextField.placeholderText" to a string)

This commit is contained in:
Karl Tauber
2019-12-17 18:08:45 +01:00
parent e4f7fed523
commit 62765ab6ca
11 changed files with 187 additions and 10 deletions

View File

@@ -62,21 +62,25 @@ class BasicComponentsPanel
JLabel spinnerLabel = new JLabel();
JSpinner spinner1 = new JSpinner();
JSpinner spinner2 = new JSpinner();
JComboBox<String> comboBox6 = new JComboBox<>();
JLabel textFieldLabel = new JLabel();
JTextField textField1 = new JTextField();
JTextField textField2 = new JTextField();
JTextField textField3 = new JTextField();
JTextField textField4 = new JTextField();
JTextField textField6 = new JTextField();
JLabel formattedTextFieldLabel = new JLabel();
JFormattedTextField formattedTextField1 = new JFormattedTextField();
JFormattedTextField formattedTextField2 = new JFormattedTextField();
JFormattedTextField formattedTextField3 = new JFormattedTextField();
JFormattedTextField formattedTextField4 = new JFormattedTextField();
JFormattedTextField formattedTextField5 = new JFormattedTextField();
JLabel passwordFieldLabel = new JLabel();
JPasswordField passwordField1 = new JPasswordField();
JPasswordField passwordField2 = new JPasswordField();
JPasswordField passwordField3 = new JPasswordField();
JPasswordField passwordField4 = new JPasswordField();
JPasswordField passwordField5 = new JPasswordField();
JLabel textAreaLabel = new JLabel();
JScrollPane scrollPane1 = new JScrollPane();
JTextArea textArea1 = new JTextArea();
@@ -304,6 +308,11 @@ class BasicComponentsPanel
spinner2.setEnabled(false);
add(spinner2, "cell 2 5,growx");
//---- comboBox6 ----
comboBox6.setEditable(true);
comboBox6.putClientProperty("JTextField.placeholderText", "placeholder");
add(comboBox6, "cell 5 5,growx");
//---- textFieldLabel ----
textFieldLabel.setText("JTextField:");
add(textFieldLabel, "cell 0 6");
@@ -328,6 +337,10 @@ class BasicComponentsPanel
textField4.setEditable(false);
add(textField4, "cell 4 6,growx");
//---- textField6 ----
textField6.putClientProperty("JTextField.placeholderText", "placeholder");
add(textField6, "cell 5 6,growx");
//---- formattedTextFieldLabel ----
formattedTextFieldLabel.setText("JFormattedTextField:");
add(formattedTextFieldLabel, "cell 0 7");
@@ -352,6 +365,10 @@ class BasicComponentsPanel
formattedTextField4.setEditable(false);
add(formattedTextField4, "cell 4 7,growx");
//---- formattedTextField5 ----
formattedTextField5.putClientProperty("JTextField.placeholderText", "placeholder");
add(formattedTextField5, "cell 5 7,growx");
//---- passwordFieldLabel ----
passwordFieldLabel.setText("JPasswordField:");
add(passwordFieldLabel, "cell 0 8");
@@ -376,6 +393,10 @@ class BasicComponentsPanel
passwordField4.setEditable(false);
add(passwordField4, "cell 4 8,growx");
//---- passwordField5 ----
passwordField5.putClientProperty("JTextField.placeholderText", "placeholder");
add(passwordField5, "cell 5 8,growx");
//---- textAreaLabel ----
textAreaLabel.setText("JTextArea:");
add(textAreaLabel, "cell 0 9");

View File

@@ -253,6 +253,16 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 5,growx"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "comboBox6"
"editable": true
"$client.JTextField.placeholderText": "placeholder"
auxiliary() {
"JavaCodeGenerator.typeParameters": "String"
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 5,growx"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "textFieldLabel"
"text": "JTextField:"
@@ -287,6 +297,12 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 6,growx"
} )
add( new FormComponent( "javax.swing.JTextField" ) {
name: "textField6"
"$client.JTextField.placeholderText": "placeholder"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 6,growx"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "formattedTextFieldLabel"
"text": "JFormattedTextField:"
@@ -321,6 +337,12 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 7,growx"
} )
add( new FormComponent( "javax.swing.JFormattedTextField" ) {
name: "formattedTextField5"
"$client.JTextField.placeholderText": "placeholder"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 7,growx"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "passwordFieldLabel"
"text": "JPasswordField:"
@@ -355,6 +377,12 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 8,growx"
} )
add( new FormComponent( "javax.swing.JPasswordField" ) {
name: "passwordField5"
"$client.JTextField.placeholderText": "placeholder"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 8,growx"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "textAreaLabel"
"text": "JTextArea:"