Java 类javax.swing.JPasswordField 实例源码

项目:incubator-netbeans    文件:CodeSetupPanel.java   
@Override
public TableCellEditor getCellEditor(int row, int column) {
    if(showParamTypes) {
        String paramName = (String) tableModel.getValueAt(row, 0);
        Class type = (column == 2) ? (Class) tableModel.getValueAt(row, 1) : Boolean.class;

        if (Enum.class.isAssignableFrom(type)) {
            JComboBox combo = new JComboBox(type.getEnumConstants());
            return new DefaultCellEditor(combo);
        } else if (type == Boolean.class || type == Boolean.TYPE) {
            JCheckBox cb = new JCheckBox();
            cb.setHorizontalAlignment(JLabel.CENTER);
            cb.setBorderPainted(true);
            return new DefaultCellEditor(cb);
        } else if (paramName.toLowerCase().contains(Constants.PASSWORD)) {
            return new DefaultCellEditor(new JPasswordField());
        }
    }

    return super.getCellEditor(row, column);
}
项目:incubator-netbeans    文件:CodeSetupPanel.java   
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, 
        boolean hasFocus, int row, int column) {
    Component ret = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    String paramName = (String) tableModel.getValueAt(row, 0);

    if (value == null) {
        return new JLabel(NbBundle.getMessage(CodeSetupPanel.class, "LBL_NotSet"));
    } else if (value instanceof Class) {
        return new JLabel(((Class) value).getName());
    } else if (value instanceof Boolean) {
        JCheckBox cb = new JCheckBox();
        cb.setHorizontalAlignment(JLabel.CENTER);
        cb.setBorderPainted(true);
        cb.setSelected((Boolean) value);
        return cb;
    } else if (paramName.contains(Constants.PASSWORD)) {
        return new JPasswordField((String) value);
    } 
    return ret;
}
项目:dracoon-dropzone    文件:Dropzone.java   
/**
 * Show master password dialog if enabled
 */
private void showMasterPasswordEntry() {
    ConfigIO cfg = ConfigIO.getInstance();
    if (cfg.isMasterPwdEnabled()) {
        JPanel panel = new JPanel(new BorderLayout());
        JPasswordField pf = new JPasswordField();
        panel.setBorder(new EmptyBorder(0, 10, 0, 10));
        panel.add(pf, BorderLayout.NORTH);
        JFrame frame = new JFrame();
        frame.setAlwaysOnTop(true);

        int option = JOptionPane.showConfirmDialog(frame, panel, I18n.get("main.start.requestmasterpwd"),
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        frame.dispose();
        if (option == JOptionPane.OK_OPTION) {
            cfg.setMasterPassword(new String(pf.getPassword()));
        } else {
            // TODO show config dialog
        }
    }
}
项目:dracoon-dropzone    文件:Dropzone.java   
/**
 * Show password dialog if enabled
 */
private String showPasswordDialog() {
    JPanel panel = new JPanel(new BorderLayout());
    JPasswordField pf = new JPasswordField();
    panel.setBorder(new EmptyBorder(0, 10, 0, 10));
    panel.add(pf, BorderLayout.NORTH);
    JFrame frame = new JFrame();
    frame.setAlwaysOnTop(true);
    pf.requestFocus();

    int option = JOptionPane.showConfirmDialog(frame, panel, I18n.get("main.start.sharelinkpwd"),
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    frame.dispose();
    if (option == JOptionPane.OK_OPTION) {
        return new String(pf.getPassword());
    } else {
        return null;
    }
}
项目:KernelHive    文件:UserCredentialsPanel.java   
public UserCredentialsPanel(){
    setSize(new Dimension(900, 300));
    setPreferredSize(new Dimension(900, 300));
    setMinimumSize(new Dimension(450, 300));
    setLayout(null);

    JLabel lblUsername = new JLabel("Username");
    lblUsername.setBounds(12, 12, 86, 15);
    add(lblUsername);

    JLabel lblPassword = new JLabel("Password");
    lblPassword.setBounds(12, 49, 70, 15);
    add(lblPassword);

    usernameField = new JTextField();
    usernameField.setBounds(116, 10, 114, 19);
    add(usernameField);
    usernameField.setColumns(10);

    passwordField = new JPasswordField();
    passwordField.setBounds(116, 47, 114, 19);
    add(passwordField);
}
项目:Equella    文件:AbstractTLFPlugin.java   
@Override
public void initGUI()
{
    userField = new JTextField();
    passField = new JPasswordField();

    liveOnly = new JCheckBox();
    harvestLearningObjects = new JCheckBox();
    harvestResources = new JCheckBox();

    panel.addComponent(new JLabel(getString(getPluginsFieldString())));
    panel.addNameAndComponent(getString("detailstab.user"), userField);
    panel.addNameAndComponent(getString("detailstab.pass"), passField);

    panel.addNameAndComponent(getString("loraxplugin.live"), liveOnly);
    panel.addNameAndComponent(getString("loraxplugin.harvestlo"),
        harvestLearningObjects);
    panel.addNameAndComponent(getString("loraxplugin.harvestre"),
        harvestResources);

}
项目:zencash-swing-wallet-ui    文件:PasswordEncryptionDialog.java   
public PasswordEncryptionDialog(JFrame parent)
{
    super(parent);

    this.upperLabel.setText(
        "<html>The wallet.dat file will be encrypted with a password. If the operation is successful, " +
           "zend will automatically stop and will need to be restarted. The GUI wallet will also be stopped " +
           "and will need to be restarted. Please enter the password:</html>");

    JLabel confLabel = new JLabel("Confirmation: ");
    this.freeSlotPanel.add(confLabel);
    this.freeSlotPanel.add(passwordConfirmationField = new JPasswordField(30));
    this.passwordLabel.setPreferredSize(confLabel.getPreferredSize());

    JLabel dividerLabel = new JLabel("   ");
    dividerLabel.setFont(new Font("Helvetica", Font.PLAIN, 8));
    this.freeSlotPanel2.add(dividerLabel);

    this.setSize(460, 270);
    this.validate();
    this.repaint();
}
项目:komodoGUI    文件:PasswordEncryptionDialog.java   
public PasswordEncryptionDialog(JFrame parent)
{
    super(parent);

    this.upperLabel.setText(
        "<html>The wallet.dat file will be encrypted with a password. If the operation is successful, " +
           "zcashd will automatically stop and will need to be restarted. The GUI wallet will also be stopped " +
           "and will need to be restarted. Please enter the password:</html>");

    JLabel confLabel = new JLabel("Confirmation: ");
    this.freeSlotPanel.add(confLabel);
    this.freeSlotPanel.add(passwordConfirmationField = new JPasswordField(30));
    this.passwordLabel.setPreferredSize(confLabel.getPreferredSize());

    JLabel dividerLabel = new JLabel("   ");
    dividerLabel.setFont(new Font("Helvetica", Font.PLAIN, 8));
    this.freeSlotPanel2.add(dividerLabel);

    this.setSize(460, 270);
    this.validate();
    this.repaint();
}
项目:jiracli    文件:CredentialsPanel.java   
private CredentialsPanel(String username, String url) {
    this.url = url;
    this.usernamePassword = new JRadioButton("Username and password");
    this.usernamePassword.addActionListener(new RadioButtonListener());
    this.anonymous = new JRadioButton("Anonymous access");
    this.anonymous.addActionListener(new RadioButtonListener());
    this.buttonGroup = new ButtonGroup();
    this.buttonGroup.add(usernamePassword);
    this.buttonGroup.add(anonymous);
    this.usernameLabel = new JLabel("Username:");
    this.username = new JTextField(Objects.toString(username, ""), 20);
    this.passwordLabel = new JLabel("Password:");
    this.password = new JPasswordField(20);
    if (username == null || username.isEmpty()) {
        this.anonymous.setSelected(true);
    } else {
        this.usernamePassword.setSelected(true);
        this.password.addAncestorListener(new RequestFocusListener());
    }
    radioButtonToggled();
    layoutComponents();
}
项目:OpenJSharp    文件:PasswordView.java   
/**
 * Renders the given range in the model as normal unselected
 * text.  This sets the foreground color and echos the characters
 * using the value returned by getEchoChar().
 *
 * @param g the graphics context
 * @param x the starting X coordinate &gt;= 0
 * @param y the starting Y coordinate &gt;= 0
 * @param p0 the starting offset in the model &gt;= 0
 * @param p1 the ending offset in the model &gt;= p0
 * @return the X location of the end of the range &gt;= 0
 * @exception BadLocationException if p0 or p1 are out of range
 */
protected int drawUnselectedText(Graphics g, int x, int y,
                                 int p0, int p1) throws BadLocationException {

    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.drawUnselectedText(g, x, y, p0, p1);
        }
        if (f.isEnabled()) {
            g.setColor(f.getForeground());
        }
        else {
            g.setColor(f.getDisabledTextColor());
        }
        char echoChar = f.getEchoChar();
        int n = p1 - p0;
        for (int i = 0; i < n; i++) {
            x = drawEchoCharacter(g, x, y, echoChar);
        }
    }
    return x;
}
项目:OpenJSharp    文件:PasswordView.java   
/**
 * Renders the given range in the model as selected text.  This
 * is implemented to render the text in the color specified in
 * the hosting component.  It assumes the highlighter will render
 * the selected background.  Uses the result of getEchoChar() to
 * display the characters.
 *
 * @param g the graphics context
 * @param x the starting X coordinate &gt;= 0
 * @param y the starting Y coordinate &gt;= 0
 * @param p0 the starting offset in the model &gt;= 0
 * @param p1 the ending offset in the model &gt;= p0
 * @return the X location of the end of the range &gt;= 0
 * @exception BadLocationException if p0 or p1 are out of range
 */
protected int drawSelectedText(Graphics g, int x,
                               int y, int p0, int p1) throws BadLocationException {
    g.setColor(selected);
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.drawSelectedText(g, x, y, p0, p1);
        }
        char echoChar = f.getEchoChar();
        int n = p1 - p0;
        for (int i = 0; i < n; i++) {
            x = drawEchoCharacter(g, x, y, echoChar);
        }
    }
    return x;
}
项目:OpenJSharp    文件:PasswordView.java   
/**
 * Provides a mapping from the document model coordinate space
 * to the coordinate space of the view mapped to it.
 *
 * @param pos the position to convert &gt;= 0
 * @param a the allocated region to render into
 * @return the bounding box of the given position
 * @exception BadLocationException  if the given position does not
 *   represent a valid location in the associated document
 * @see View#modelToView
 */
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.modelToView(pos, a, b);
        }
        char echoChar = f.getEchoChar();
        FontMetrics m = f.getFontMetrics(f.getFont());

        Rectangle alloc = adjustAllocation(a).getBounds();
        int dx = (pos - getStartOffset()) * m.charWidth(echoChar);
        alloc.x += dx;
        alloc.width = 1;
        return alloc;
    }
    return null;
}
项目:OpenJSharp    文件:PasswordView.java   
/**
 * Provides a mapping from the view coordinate space to the logical
 * coordinate space of the model.
 *
 * @param fx the X coordinate &gt;= 0.0f
 * @param fy the Y coordinate &gt;= 0.0f
 * @param a the allocated region to render into
 * @return the location within the model that best represents the
 *  given point in the view
 * @see View#viewToModel
 */
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
    bias[0] = Position.Bias.Forward;
    int n = 0;
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.viewToModel(fx, fy, a, bias);
        }
        char echoChar = f.getEchoChar();
        int charWidth = f.getFontMetrics(f.getFont()).charWidth(echoChar);
        a = adjustAllocation(a);
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
                          a.getBounds();
        n = (charWidth > 0 ?
             ((int)fx - alloc.x) / charWidth : Integer.MAX_VALUE);
        if (n < 0) {
            n = 0;
        }
        else if (n > (getStartOffset() + getDocument().getLength())) {
            n = getDocument().getLength() - getStartOffset();
        }
    }
    return getStartOffset() + n;
}
项目:LANClipboard    文件:EnterPassword.java   
public static String run() {    // SOURCE: https://goo.gl/5pFXao
    JPanel panel = new JPanel();
    JLabel label = new JLabel("This server is protected with a password.");
    JPasswordField pass = new JPasswordField(10);
    panel.add(label);
    panel.add(pass);
    String[] options = new String[]{"OK", "Cancel"};
    int option = JOptionPane.showOptionDialog(null, panel, "Enter password",
            JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
            null, options, options[0]);
    if(option == 0) { // OK button
        char[] password = pass.getPassword();
        return new String(password);
    } else {
        return null;
    }
}
项目:jdk8u-jdk    文件:PasswordView.java   
/**
 * Renders the given range in the model as normal unselected
 * text.  This sets the foreground color and echos the characters
 * using the value returned by getEchoChar().
 *
 * @param g the graphics context
 * @param x the starting X coordinate &gt;= 0
 * @param y the starting Y coordinate &gt;= 0
 * @param p0 the starting offset in the model &gt;= 0
 * @param p1 the ending offset in the model &gt;= p0
 * @return the X location of the end of the range &gt;= 0
 * @exception BadLocationException if p0 or p1 are out of range
 */
protected int drawUnselectedText(Graphics g, int x, int y,
                                 int p0, int p1) throws BadLocationException {

    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.drawUnselectedText(g, x, y, p0, p1);
        }
        if (f.isEnabled()) {
            g.setColor(f.getForeground());
        }
        else {
            g.setColor(f.getDisabledTextColor());
        }
        char echoChar = f.getEchoChar();
        int n = p1 - p0;
        for (int i = 0; i < n; i++) {
            x = drawEchoCharacter(g, x, y, echoChar);
        }
    }
    return x;
}
项目:jdk8u-jdk    文件:PasswordView.java   
/**
 * Renders the given range in the model as selected text.  This
 * is implemented to render the text in the color specified in
 * the hosting component.  It assumes the highlighter will render
 * the selected background.  Uses the result of getEchoChar() to
 * display the characters.
 *
 * @param g the graphics context
 * @param x the starting X coordinate &gt;= 0
 * @param y the starting Y coordinate &gt;= 0
 * @param p0 the starting offset in the model &gt;= 0
 * @param p1 the ending offset in the model &gt;= p0
 * @return the X location of the end of the range &gt;= 0
 * @exception BadLocationException if p0 or p1 are out of range
 */
protected int drawSelectedText(Graphics g, int x,
                               int y, int p0, int p1) throws BadLocationException {
    g.setColor(selected);
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.drawSelectedText(g, x, y, p0, p1);
        }
        char echoChar = f.getEchoChar();
        int n = p1 - p0;
        for (int i = 0; i < n; i++) {
            x = drawEchoCharacter(g, x, y, echoChar);
        }
    }
    return x;
}
项目:jdk8u-jdk    文件:PasswordView.java   
/**
 * Provides a mapping from the document model coordinate space
 * to the coordinate space of the view mapped to it.
 *
 * @param pos the position to convert &gt;= 0
 * @param a the allocated region to render into
 * @return the bounding box of the given position
 * @exception BadLocationException  if the given position does not
 *   represent a valid location in the associated document
 * @see View#modelToView
 */
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.modelToView(pos, a, b);
        }
        char echoChar = f.getEchoChar();
        FontMetrics m = f.getFontMetrics(f.getFont());

        Rectangle alloc = adjustAllocation(a).getBounds();
        int dx = (pos - getStartOffset()) * m.charWidth(echoChar);
        alloc.x += dx;
        alloc.width = 1;
        return alloc;
    }
    return null;
}
项目:jdk8u-jdk    文件:PasswordView.java   
/**
 * Provides a mapping from the view coordinate space to the logical
 * coordinate space of the model.
 *
 * @param fx the X coordinate &gt;= 0.0f
 * @param fy the Y coordinate &gt;= 0.0f
 * @param a the allocated region to render into
 * @return the location within the model that best represents the
 *  given point in the view
 * @see View#viewToModel
 */
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
    bias[0] = Position.Bias.Forward;
    int n = 0;
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.viewToModel(fx, fy, a, bias);
        }
        char echoChar = f.getEchoChar();
        int charWidth = f.getFontMetrics(f.getFont()).charWidth(echoChar);
        a = adjustAllocation(a);
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
                          a.getBounds();
        n = (charWidth > 0 ?
             ((int)fx - alloc.x) / charWidth : Integer.MAX_VALUE);
        if (n < 0) {
            n = 0;
        }
        else if (n > (getStartOffset() + getDocument().getLength())) {
            n = getDocument().getLength() - getStartOffset();
        }
    }
    return getStartOffset() + n;
}
项目:jdk8u-jdk    文件:PasswordView.java   
/**
 * Determines the preferred span for this view along an
 * axis.
 *
 * @param axis may be either View.X_AXIS or View.Y_AXIS
 * @return   the span the view would like to be rendered into &gt;= 0.
 *           Typically the view is told to render into the span
 *           that is returned, although there is no guarantee.
 *           The parent may choose to resize or break the view.
 */
public float getPreferredSpan(int axis) {
    switch (axis) {
    case View.X_AXIS:
        Container c = getContainer();
        if (c instanceof JPasswordField) {
            JPasswordField f = (JPasswordField) c;
            if (f.echoCharIsSet()) {
                char echoChar = f.getEchoChar();
                FontMetrics m = f.getFontMetrics(f.getFont());
                Document doc = getDocument();
                return m.charWidth(echoChar) * getDocument().getLength();
            }
        }
    }
    return super.getPreferredSpan(axis);
}
项目:openjdk-jdk10    文件:PasswordView.java   
/**
 * Provides a mapping from the document model coordinate space
 * to the coordinate space of the view mapped to it.
 *
 * @param pos the position to convert &gt;= 0
 * @param a the allocated region to render into
 * @return the bounding box of the given position
 * @exception BadLocationException  if the given position does not
 *   represent a valid location in the associated document
 * @see View#modelToView
 */
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (! f.echoCharIsSet()) {
            return super.modelToView(pos, a, b);
        }
        char echoChar = f.getEchoChar();
        FontMetrics m = f.getFontMetrics(f.getFont());

        Rectangle alloc = adjustAllocation(a).getBounds();
        int dx = (pos - getStartOffset()) * m.charWidth(echoChar);
        alloc.x += dx;
        alloc.width = 1;
        return alloc;
    }
    return null;
}
项目:polyevent    文件:LoginView.java   
/**
 * Affiche les �lements graphiques sur la fen�tre
 */
private void afficher() {
    this.panPrinc = new JPanel();
    this.panPrinc.setLayout(new BoxLayout(this.panPrinc, BoxLayout.PAGE_AXIS));

    //Label identifiant
    JLabel labIdentifiant = new JLabel("Identifiant");
    labIdentifiant.setFont(new Font("Arial", Font.PLAIN, 20));
    labIdentifiant.setAlignmentX(Component.CENTER_ALIGNMENT);

    //Label mot de passe
    JLabel labMdp = new JLabel("Mot de passe");
    labMdp.setFont(new Font("Arial", Font.PLAIN, 20));
    labMdp.setAlignmentX(Component.CENTER_ALIGNMENT);

    //Champ de l'identifiant
    this.fieldName = new JTextField();
    this.fieldName.setPreferredSize(new Dimension(150,25));
    this.fieldName.setAlignmentX(Component.CENTER_ALIGNMENT);

    //Champ du mot de passe
    this.fieldPassword = new JPasswordField();
    this.fieldPassword.setEchoChar('*');
    this.fieldPassword.setPreferredSize(new Dimension(150,25));
    this.fieldPassword.setAlignmentX(Component.CENTER_ALIGNMENT);

    //Bouton connecter
    butConnecter = new JButton();
    butConnecter.setAlignmentX(Component.CENTER_ALIGNMENT);

    this.panPrinc.add(Box.createVerticalStrut(180));
    this.panPrinc.add(labIdentifiant);
    this.panPrinc.add(this.fieldName);
    this.panPrinc.add(Box.createVerticalStrut(10));
    this.panPrinc.add(labMdp);
    this.panPrinc.add(this.fieldPassword);
    this.panPrinc.add(Box.createVerticalStrut(40));
    this.panPrinc.add(butConnecter);
}
项目:Dahlem_SER316    文件:LoginDialogTest.java   
/**
 * Tests to ensure account is not generated when it shouldn't be. For
 * example: Differing passwords or account already exists. This does not
 * validate the account creation process details.
 */
@Test
public void testAccountCreation() {
    JTextField usernameField = dlg.getUsernameField();
    JPasswordField passPrimary = dlg.getPasswordFieldPrimary();
    JPasswordField passVerify = dlg.getPasswordFieldVerify();
    JButton button = dlg.getBtnCreateNewAccount();

    // Test account created no password
    usernameField.setText("HeyTestGuy1");
    passPrimary.setText("");
    passVerify.setText("");
    button.doClick();
    assertTrue(AccountManager.userExists("HeyTestGuy1"));

    // Test account NOT created - mismatched password
    usernameField.setText("HeyTestGuy2");
    passPrimary.setText("ardvark");
    passVerify.setText("");
    button.doClick();
    assertFalse(AccountManager.userExists("HeyTestGuy2"));

    //Test all correct values.
    usernameField.setText("HeyTestGuy3");
    passPrimary.setText("ardvark");
    passVerify.setText("ardvark");
    button.doClick();
    assertTrue(AccountManager.userExists("HeyTestGuy3"));

    assertTrue(AccountManager.removeUserAccount("HeyTestGuy1"));
    assertTrue(AccountManager.removeUserAccount("HeyTestGuy3"));
}
项目:JDigitalSimulator    文件:Guitilities.java   
public static String showPasswordDialog(Component component, String text, String title) {
    JPasswordField field = new JPasswordField(); field.setEchoChar('\u25CF');
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(createLabel(text));
    panel.add(field);
    if(JOptionPane.showConfirmDialog(component, panel, title, JOptionPane.OK_CANCEL_OPTION)==JOptionPane.OK_OPTION)
        return new String(field.getPassword());
    else return null;
}
项目:openjdk-jdk10    文件:JPasswordFieldOperator.java   
/**
 * Maps {@code JPasswordField.setEchoChar(char)} through queue
 */
public void setEchoChar(final char c) {
    runMapping(new MapVoidAction("setEchoChar") {
        @Override
        public void map() {
            ((JPasswordField) getSource()).setEchoChar(c);
        }
    });
}
项目:LivroJavaComoProgramar10Edicao    文件:TextFieldFrame.java   
public TextFieldFrame()
{
   super("Testing JTextField and JPasswordField");
   setLayout(new FlowLayout());

   // construct textfield with 10 columns
   textField1 = new JTextField(10); 
   add(textField1); // add textField1 to JFrame

   // construct textfield with default text
   textField2 = new JTextField("Enter text here");
   add(textField2); // add textField2 to JFrame

   // construct textfield with default text and 21 columns
   textField3 = new JTextField("Uneditable text field", 21);
   textField3.setEditable(false); // disable editing
   add(textField3); // add textField3 to JFrame

   // construct passwordfield with default text
   passwordField = new JPasswordField("Hidden text");
   add(passwordField); // add passwordField to JFrame

   // register event handlers
   TextFieldHandler handler = new TextFieldHandler();
   textField1.addActionListener(handler);
   textField2.addActionListener(handler);
   textField3.addActionListener(handler);
   passwordField.addActionListener(handler);
}
项目:openjdk-jdk10    文件:JPasswordFieldOperator.java   
/**
 * Maps {@code JPasswordField.getPassword()} through queue
 */
public char[] getPassword() {
    return ((char[]) runMapping(new MapAction<Object>("getPassword") {
        @Override
        public Object map() {
            return ((JPasswordField) getSource()).getPassword();
        }
    }));
}
项目:Hotel-Properties-Management-System    文件:ChangePasswordWindow.java   
public void keyListenerForFields(JPasswordField passwordField) {
    KeyAdapter myAdapter = new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            infoLabel.setText(null);
            markerLbl.setVisible(false);
            super.keyTyped(e);
        }
    };
    passwordField.addKeyListener(myAdapter);
}
项目:Equella    文件:ProxyDetailsDialog.java   
private void setupCredentials()
{
    JLabel usernameLabel = new JLabel("Username:");
    JLabel passwordLabel = new JLabel("Password:");

    usernameField = new JTextField();
    passwordField = new JPasswordField();

    usernameField.addKeyListener(this);
    passwordField.addKeyListener(this);

    final int width1 = usernameLabel.getPreferredSize().width;
    final int width2 = passwordLabel.getPreferredSize().width;
    final int width3 = Math.max(width1, width2);
    final int height1 = usernameField.getPreferredSize().height;

    final int[] rows = {height1, height1};
    final int[] cols = {width3, TableLayout.FILL};

    credentials = new JGroup("Server requires authentication", false);
    credentials.addActionListener(this);
    credentials.setInnerLayout(new TableLayout(rows, cols));

    credentials.addInner(usernameLabel, new Rectangle(0, 0, 1, 1));
    credentials.addInner(passwordLabel, new Rectangle(0, 1, 1, 1));
    credentials.addInner(usernameField, new Rectangle(1, 0, 1, 1));
    credentials.addInner(passwordField, new Rectangle(1, 1, 1, 1));

    credentials.setSelected(false);
}
项目:Dahlem_SER316    文件:LoginDialog.java   
/**
 * Occurs when sign in button is pressed and then utilizes the account
 * manager to verify the name and password fields match their respective
 * account file.
 */
protected void loginToAccount() {
    JTextField name = getUsernameField();
    JPasswordField pw = getPasswordFieldPrimary();
    if (AccountManager.verifyAccountHashedPassword(name.getText(), String.valueOf(pw.getPassword()))) {
        App.showWindow();
        this.dispose();
    } else {
        errorLabel.setText("Failed to log in.");
        errorLabel.setForeground(Color.red);
    }
    repaint();
}
项目:Equella    文件:EQUELLAPlugin.java   
@Override
public void initGUI()
{
    userField = new JTextField();
    passField = new JPasswordField();

    serverField = new JTextField();

    liveOnly = new JCheckBox();

    collectionField = new JComboBox<NameValue>();
    collectionField.setEditable(false);

    JButton getCollections = new JButton(s("getcollections"));
    getCollections.addActionListener(this);

    final int width = getCollections.getPreferredSize().width;
    final int height = getCollections.getPreferredSize().height;

    final int[] rows = {height};
    final int[] cols = new int[]{TableLayout.FILL, width};

    JPanel collPanel = new JPanel();
    collPanel.setLayout(new TableLayout(rows, cols, 5, 5));

    collPanel.add(collectionField, new Rectangle(0, 0, 1, 1));
    collPanel.add(getCollections, new Rectangle(1, 0, 1, 1));

    panel.addComponent(new JLabel(s("settings")));

    panel.addNameAndComponent(s("server"), serverField);

    panel.addNameAndComponent(getString("detailstab.user"), userField);
    panel.addNameAndComponent(getString("detailstab.pass"), passField);

    panel.addNameAndComponent(s("remotecollection"), collPanel);
    panel.addNameAndComponent(s("live"), liveOnly);
}
项目:Equella    文件:CanvasSettingsPanel.java   
protected void setupGui()
{
    final JLabel canvasUrlLabel = new JLabel(getString("label.canvasurl"));
    final JLabel clientIdLabel = new JLabel(getString("label.clientid"));
    final JLabel secretLabel = new JLabel(getString("label.secret"));
    preamble = new JLabel(getString("preamble", CANVAS_SIGNUP_URL));
    preamble.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    preamble.addMouseListener(this);

    canvasUrl = new JTextField(20);
    clientId = new JTextField(20);
    secret = new JPasswordField(20);
    bypassLogon = new JCheckBox();
    bypassLogon.setText(getString("label.bypasslogon"));

    final LayoutManager layout = new MigLayout("wrap", "[fill][fill,grow]");
    setLayout(layout);

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(preamble, "span 2, gapbottom 20");
    add(canvasUrlLabel);
    add(canvasUrl);
    add(clientIdLabel);
    add(clientId);
    add(secretLabel);
    add(secret);
    add(bypassLogon, "span 2");

    validate();
}
项目:ramus    文件:AttributeEditorDialog.java   
private void setEditsAction(final Container con) {
      if (con instanceof JSpinner)
          return;

/*
       * if(con instanceof JSplitPane){
 * setEditsAction(((JSplitPane)con).getLeftComponent());
 * setEditsAction(((JSplitPane)con).getRightComponent()); return; }
 */

      for (int i = 0; i < con.getComponentCount(); i++) {
          if (con.getComponent(i) instanceof Container)
              setEditsAction((Container) con.getComponent(i));
          final Component container = con.getComponent(i);
          if (container instanceof JTextField) {
              ((JTextField) container).addActionListener(listener);
          } else if (container instanceof JPasswordField) {
              ((JPasswordField) container).addActionListener(listener);
          }

          if (container instanceof JList
                  && !(container instanceof JTableHeader)) {
              ((JList) container).addMouseListener(new MouseAdapter() {

                  @Override
                  public void mouseClicked(final MouseEvent e) {
                      if (e.getButton() == MouseEvent.BUTTON1
                              && e.getClickCount() > 1)
                          panel.ok();
                  }

              });
          }
      }
  }
项目:ramus    文件:BaseDialog.java   
private void setEditsAction(final Container con) {
      if (con instanceof JSpinner)
          return;

/*
       * if(con instanceof JSplitPane){
 * setEditsAction(((JSplitPane)con).getLeftComponent());
 * setEditsAction(((JSplitPane)con).getRightComponent()); return; }
 */

      for (int i = 0; i < con.getComponentCount(); i++) {
          if (con.getComponent(i) instanceof Container)
              setEditsAction((Container) con.getComponent(i));
          final Component container = con.getComponent(i);
          if (container instanceof JTextField) {
              processTextField((JTextField) container);
          } else if (container instanceof JPasswordField) {
              ((JPasswordField) container).addActionListener(listener);
          }
          if (container instanceof JTextComponent) {
              addUndoFunctions((JTextComponent) container);
          }
          if (container instanceof JList
                  && !(container instanceof JTableHeader)) {
              ((JList) container).addMouseListener(new MouseAdapter() {

                  @Override
                  public void mouseClicked(final MouseEvent e) {
                      if (e.getButton() == MouseEvent.BUTTON1
                              && e.getClickCount() > 1)
                          onOk();
                  }

              });
          }
      }
  }
项目:ramus    文件:BaseDialog.java   
private void setEditsAction(final Container con) {
      if (con instanceof JSpinField)
          return;

/*
       * if(con instanceof JSplitPane){
 * setEditsAction(((JSplitPane)con).getLeftComponent());
 * setEditsAction(((JSplitPane)con).getRightComponent()); return; }
 */

      for (int i = 0; i < con.getComponentCount(); i++) {
          if (con.getComponent(i) instanceof Container)
              setEditsAction((Container) con.getComponent(i));
          final Component container = con.getComponent(i);
          if (container instanceof JTextField) {
              processTextField((JTextField) container);
          } else if (container instanceof JPasswordField) {
              ((JPasswordField) container).addActionListener(listener);
          }
          if (container instanceof JTextComponent) {
              addUndoFunctions((JTextComponent) container);
          }
          if (container instanceof JList
                  && !(container instanceof com.ramussoft.gui.qualifier.table.TableRowHeader)) {
              ((JList) container).addMouseListener(new MouseAdapter() {

                  @Override
                  public void mouseClicked(final MouseEvent e) {
                      if (e.getButton() == MouseEvent.BUTTON1
                              && e.getClickCount() > 1)
                          onOk();
                  }

              });
          }
      }
  }
项目:BachSys    文件:TelaCadastroUsuario.java   
@Override
public void construirTela(){

    lbUsuario = new JLabel("Usuário:");
    adicionarComponente(lbUsuario, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, 0, 0, 1 ,1);
    lbEmail = new JLabel("E-mail:");
    adicionarComponente(lbEmail, GridBagConstraints.CENTER, GridBagConstraints.NONE, 1, 0, 1 ,1);
    lbSenha = new JLabel("Senha:");
    adicionarComponente(lbSenha, GridBagConstraints.CENTER, GridBagConstraints.NONE, 2, 0, 1 ,1);
    lbConfirmarSenha = new JLabel("Confirmar Senha:");
    adicionarComponente(lbConfirmarSenha, GridBagConstraints.CENTER, GridBagConstraints.NONE, 2, 2, 1 ,1);

    txtUsuario = new JTextField(10);
    adicionarComponente(txtUsuario, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, 0, 1, 3 ,1);
    txtEmail = new JTextField(10);
    adicionarComponente(txtEmail, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, 1, 1, 3 ,1);
    txtSenha = new JPasswordField(10);
    adicionarComponente(txtSenha, GridBagConstraints.CENTER, GridBagConstraints.NONE, 2, 1, 1 ,1);
    txtConfirmarSenha = new JPasswordField(10);
    adicionarComponente(txtConfirmarSenha, GridBagConstraints.CENTER, GridBagConstraints.NONE, 2, 3, 1 ,1);

    btnCancelar = new JButton("Cancelar");        
    btnRegistrar = new JButton("Enviar");

    painelBotoes = new JPanel();
    painelBotoes.add(btnCancelar);
    painelBotoes.add(btnRegistrar);
    adicionarComponente(painelBotoes, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, 3, 0, 4,1);


}
项目:openjdk-jdk10    文件:JPasswordFieldOperator.java   
@Override
public Hashtable<String, Object> getDump() {
    Hashtable<String, Object> result = super.getDump();
    result.put(ECHO_CHAR_DPROP,
            Character.toString(((JPasswordField) getSource()).getEchoChar()));
    return result;
}
项目:OpenJSharp    文件:XTextFieldPeer.java   
@Override
protected String getPropertyPrefix() {
    JTextComponent comp = getComponent();
    if (comp instanceof JPasswordField && ((JPasswordField)comp).echoCharIsSet()) {
        return "PasswordField";
    } else {
        return "TextField";
    }
}
项目:jdk8u-jdk    文件:XTextFieldPeer.java   
@Override
protected String getPropertyPrefix() {
    JTextComponent comp = getComponent();
    if (comp instanceof JPasswordField && ((JPasswordField)comp).echoCharIsSet()) {
        return "PasswordField";
    } else {
        return "TextField";
    }
}
项目:openjdk-jdk10    文件:JPasswordFieldOperator.java   
/**
 * Maps {@code JPasswordField.echoCharIsSet()} through queue
 */
public boolean echoCharIsSet() {
    return (runMapping(new MapBooleanAction("echoCharIsSet") {
        @Override
        public boolean map() {
            return ((JPasswordField) getSource()).echoCharIsSet();
        }
    }));
}
项目:openjdk-jdk10    文件:PasswordView.java   
@SuppressWarnings("deprecation")
private float drawUnselectedTextImpl(Graphics g, float x, float y,
                                     int p0, int p1,
                                     boolean useFPAPI)
        throws BadLocationException
{
    Container c = getContainer();
    if (c instanceof JPasswordField) {
        JPasswordField f = (JPasswordField) c;
        if (!f.echoCharIsSet()) {
            boolean useDrawUnselectedFPAPI = useFPAPI
                    && drawUnselectedTextOverridden
                    && g instanceof Graphics2D;
            return (useDrawUnselectedFPAPI )
                    ? super.drawUnselectedText((Graphics2D) g, x, y, p0, p1)
                    : super.drawUnselectedText(g, (int) x, (int) y, p0, p1);
        }
        if (f.isEnabled()) {
            g.setColor(f.getForeground());
        }
        else {
            g.setColor(f.getDisabledTextColor());
        }
        char echoChar = f.getEchoChar();
        int n = p1 - p0;
        boolean useEchoCharFPAPI = useFPAPI
                && drawEchoCharacterOverridden
                && g instanceof Graphics2D;
        for (int i = 0; i < n; i++) {
            x = (useEchoCharFPAPI)
                    ? drawEchoCharacter((Graphics2D) g, x, y, echoChar)
                    : drawEchoCharacter(g, (int) x, (int) y, echoChar);
        }
    }
    return x;
}