Hab eine Methode geschrieben. Viel Spaß!
Code:
public String createInputDialog() {
final JTextField tf = new JTextField();
final JLabel label = new JLabel("Enter text in here: ");
final JOptionPane optionPane = new JOptionPane(new Object[] { label, tf },
JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) {
@Override
public void selectInitialValue() {
super.selectInitialValue();
tf.requestFocus();
}
};
JDialog dialog = optionPane.createDialog(null, "Input");
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setAlwaysOnTop(true);
dialog.show();
dialog.dispose();
if(optionPane.getValue() != null) {
final int result = ((Integer) optionPane.getValue()).intValue();
if(JOptionPane.OK_OPTION == result) {
return tf.getText();
}else{
return null;
}
}
return null;
}
Habs editiert damit die Methode einen String zurück gibt falls was eingegeben wurde, wenn auf abbrechen gedrück wurde, wird null zurück gegeben.