I have my own dialog that appears with two text fields, two JLabel and "ok" JButton. A popup window is a login window. The window works fine, I just want to know how I can add a "cancel" JButton, so the user can cancel the input.
Here is my window code:
public Hashtable<String, String> login(JFrame frame) { Hashtable<String, String> logininformation = new Hashtable<String, String>(); JPanel panel = new JPanel(new BorderLayout(5, 5)); JPanel label = new JPanel(new GridLayout(0, 1, 2, 2)); label.add(new JLabel("E-Mail", SwingConstants.RIGHT)); label.add(new JLabel("Password", SwingConstants.RIGHT)); panel.add(label, BorderLayout.WEST); JPanel controls = new JPanel(new GridLayout(0, 1, 2, 2)); JTextField username = new JTextField(); controls.add(username); JPasswordField password = new JPasswordField(); controls.add(password); panel.add(controls, BorderLayout.CENTER); JOptionPane.showMessageDialog(frame, panel, "login", JOptionPane.QUESTION_MESSAGE); logininformation.put("user", username.getText()); logininformation.put("pass", new String(password.getPassword())); return logininformation; }
If you need it, here is a screenshot of the login window:

If you click on the "x" in the right corner, it will also close. But I want to cancel JButton if this is easily possible.
java jpanel jbutton joptionpane jtextfield
Gherret
source share