How would you implement a text field for entering a password in a Login dialog using Swing components?

Sandip Chitale


JPanel p = new JPanel(new GridLayout(0,1));

p.add(new JLabel("Username: "));

JTextField tf1 = new JTextField();
p.add(tf1);

p.add(new JLabel("Password: "));
JPasswordField tf2 = new JPasswordField();
p.add(tf2);

if (JOptionPane.showConfirmDialog(null // may want to pass your application frame here
                           ,p
                           ,"Login"
                           ,JOptionPane.OK_CANCEL_OPTION
                           ,JOptionPane.PLAIN_MESSAGE 
                            ) == JOptionPane.OK_OPTION) {
  // use the tf1.getText()
  // use the tf2.getText()
}

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact