Example usage for javax.swing JPasswordField setToolTipText

List of usage examples for javax.swing JPasswordField setToolTipText

Introduction

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

Prototype

@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.")
public void setToolTipText(String text) 

Source Link

Document

Registers the text to display in a tool tip.

Usage

From source file:com.eviware.soapui.support.components.SimpleForm.java

public JPasswordField appendPasswordField(String label, String tooltip) {
    JPasswordField textField = new JPasswordField();
    textField.setColumns(defaultTextFieldColumns);
    textField.setToolTipText(StringUtils.defaultIfEmpty(tooltip, null));
    textField.getAccessibleContext().setAccessibleDescription(tooltip);
    append(label, textField);/* w  w  w.  jav  a 2  s. co  m*/
    return textField;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JPasswordField createPasswordField(DocumentListener... docListeners) {
    final JPasswordField field = new JPasswordField();
    final Border oldBorder = field.getBorder();
    if (docListeners != null) {
        for (DocumentListener docListener : docListeners) {
            field.getDocument().addDocumentListener(docListener);
            field.getDocument().putProperty("owner", field);
        }//from   ww  w. ja  v  a  2 s .c  o m
    }
    final InputVerifier verifier = new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            final JPasswordField field = (JPasswordField) input;
            char[] txt = field.getPassword();
            if (txt.length == 0) {
                // Run in EDT to avoid deadlock in case this gets called
                // from not swing thread
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        field.setToolTipText(UILabels.STL50084_CANT_BE_BLANK.getDescription());
                        input.setBackground(UIConstants.INTEL_LIGHT_RED);
                        input.setBorder(BorderFactory.createLineBorder(UIConstants.INTEL_RED, 2));
                        // show tooltip immediately
                        ToolTipManager.sharedInstance()
                                .mouseMoved(new MouseEvent(field, 0, 0, 0, 0, 0, 0, false));
                    }
                });
                return false;
            } else {
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        input.setBackground(UIConstants.INTEL_WHITE);
                        input.setBorder(oldBorder);
                    }
                });
                return true;
            }
        }

    };

    DocumentListener dynamicChecker = new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

    };
    field.getDocument().addDocumentListener(dynamicChecker);

    // Add the input verifier
    field.setInputVerifier(verifier);

    return field;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a new Password Text Field/*from   ww w. ja  v a2s.  c o m*/
 * 
 * @param container - parent container
 * @param name - name of text field
 * @param initialValue - initial value of text field
 * @param mnemonic - mnemonic key
 * @param tooltip - tool tip for field
 * @param suffix - suffix text for field
 * @param labelWidth - label width 
 * @param placement - TableLayout placement
 * @param debug - turn on/off red debug borders
 * @return JPasswordField
 */
public static JPasswordField addPasswordField(Container container, String name, String initialValue,
        int mnemonic, String tooltip, String suffix, double labelWidth, String placement, boolean debug) {

    double[][] size = null;

    JPanel panel = new JPanel();
    panel.setOpaque(false);

    if (suffix.equals(""))
        size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } };
    else
        size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } };

    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JLabel label = new JLabel(name);
    label.setDisplayedMnemonic(mnemonic);

    JPasswordField result = new JPasswordField(20);
    label.setLabelFor(result);
    label.setOpaque(false);
    result.setToolTipText(tooltip);
    if (initialValue != null)
        result.setText(initialValue);

    panel.add(label, "0, 0, r, c");
    panel.add(result, "1, 0, f, c");

    if (suffix.length() != 0) {
        JLabel suffixLabel = new JLabel(" " + suffix);
        panel.add(suffixLabel, "2,0, l, c");
    }

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    container.add(panel, placement);
    return result;
}