Example usage for javax.swing JPasswordField setEditable

List of usage examples for javax.swing JPasswordField setEditable

Introduction

In this page you can find the example usage for javax.swing JPasswordField setEditable.

Prototype

@BeanProperty(description = "specifies if the text can be edited")
public void setEditable(boolean b) 

Source Link

Document

Sets the specified boolean to indicate whether or not this TextComponent should be editable.

Usage

From source file:org.pentaho.ui.xul.swing.tags.SwingTextbox.java

@Override
public Object getManagedObject() {
    if (super.getManagedObject() == null) {
        switch (this.type) {
        case PASSWORD:
            JPasswordField pass = new JPasswordField((value != null) ? value : "");
            pass.setPreferredSize(new Dimension(getWidth(), 20));
            pass.setMinimumSize(new Dimension(pass.getPreferredSize().width, pass.getPreferredSize().height));
            pass.setEditable(!readonly);
            textComp = pass;//  w  ww .j a  v a  2  s.  com
            setManagedObject(pass);
            break;
        case NUMERIC:
        default: // regular text
            if (this.multiline) {
                textArea = new JTextArea((value != null) ? value : "");
                scrollPane = new JScrollPane(textArea);
                textComp = textArea;
                setManagedObject(scrollPane);
                textArea.setEditable(!readonly);
                this.scrollPane.setMinimumSize(new Dimension(getWidth(), this.height));
                // this.scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            } else {
                textField = new JTextField((value != null) ? value : "");
                textField.setPreferredSize(new Dimension(getWidth(), textField.getPreferredSize().height));
                textField.setMinimumSize(
                        new Dimension(textField.getPreferredSize().width, textField.getPreferredSize().height));
                textField.setEditable(!readonly);
                setManagedObject(textField);
                textComp = textField;
            }

            // constrin Numeric only here
            if (this.type == TextType.NUMERIC) {
                textComp.setDocument(new NumericDocument(min, max));
            }
            textComp.setEnabled(!disabled);
            break;
        }

        textComp.addKeyListener(new KeyListener() {
            public void keyPressed(KeyEvent e) {
                oldValue = textComp.getText();
            }

            public void keyReleased(KeyEvent e) {
                if (oldValue != null && !oldValue.equals(textComp.getText())) {
                    SwingTextbox.this.changeSupport.firePropertyChange("value", oldValue,
                            SwingTextbox.this.getValue());
                    oldValue = textComp.getText();
                } else if (oldValue == null) {
                    // AWT error where sometimes the keyReleased is fired before keyPressed.
                    oldValue = textComp.getText();
                } else {
                    logger.debug("Special key pressed, ignoring");
                }
            }

            public void keyTyped(KeyEvent e) {
            }

        });

        textComp.setToolTipText(this.getTooltiptext());

        // Why do we need this here if we setup oninput in the setOninput
        // textComp.addKeyListener(new KeyAdapter() {
        //
        // public void keyReleased(KeyEvent e) {
        // invoke(onInput);
        // }
        // });
    }

    return super.getManagedObject();

}