Ich habe meine eigene Dialog Pop-up mit zwei Textfeldern, zwei JLabel und einem "ok" JButton. Das Popup ist ein Anmeldefenster. Das Fenster funktioniert perfekt Ich möchte nur wissen, wie ich einen "Abbrechen" JButton hinzufügen kann, damit der Benutzer die Anmeldung abbrechen kann.JOptionPane mit Benutzername und Passwort eingeben
Hier ist mein Code für das Fenster:
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;
}
Wenn Sie es brauchen, hier ist ein Screenshot des Anmeldefensters:
Wenn Sie auf das „x würde klicken "In der rechten Ecke schließt es auch. Aber ich möchte einen JButton abbrechen, wenn es einfach möglich ist.
- Vielen Dank für Hilfe
Das ist meine Antwort ^^ Vielen Dank! – Gerret
Gern geschehen, Kumpel. +1 an dich auch. –