Hallo Forengemeinde, ich habe eine JOptionPane mit zwei Schaltflächen. Wie kann ich die JOptionPane auf Enter reagieren lassen?
int resp = JOptionPane.showOptionDialog(null, (Object) pnl_main, "DB-Anmeldung", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, s_options, null);
String[] s_options = {"Anmelden", "Abbrechen"};
API-Doc hat gesagt.:Direct Use:
To create and use an JOptionPane directly, the standard pattern is roughly as follows:
Code:JOptionPane pane = new JOptionPane(arguments); pane.set.Xxxx(...); // Configure JDialog dialog = pane.createDialog(parentComponent, title); dialog.show(); Object selectedValue = pane.getValue(); if(selectedValue == null) return CLOSED_OPTION; //If there is not an array of option buttons: if(options == null) { if(selectedValue instanceof Integer) return ((Integer)selectedValue).intValue(); return CLOSED_OPTION; } //If there is an array of option buttons: for(int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) { if(options[counter].equals(selectedValue)) return counter; } return CLOSED_OPTION;
pane.set.Xxxx(...); // Configure
setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);