I have a JOptionPane with a string and a text field as the "message" part.
It works but I would like input focus to default to the text field when the
dialog is displayed to save the user having to click into it each time. How
can I achieve this? Do I need to actually create a JOptionPane explicitly
or subclass it?
The code is as follows:
JTextField nameTextField = new JTextField();
Object[] message = {"Enter a name:", nameTextField};
int option = JOptionPane.showOptionDialog(null, message, "Enter Name",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);

Signature
And loving it,
qu0ll
______________________________________________
qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email)
Ian Wilson - 31 Oct 2006 17:23 GMT
> I have a JOptionPane with a string and a text field as the "message" part.
> It works but I would like input focus to default to the text field when the
[quoted text clipped - 8 lines]
> int option = JOptionPane.showOptionDialog(null, message, "Enter Name",
> JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
I now use (or extend) JDialog whenever JOptionPane seems to be running
out of flexibility. The case you describe is what first prompted me to
do this.