Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set default input field in JOptionPane
    primarykey
    data
    text
    <p>I have the following code:</p> <pre><code>JTextField uname = new JTextField(defaultUser); JPasswordField passwd = new JPasswordField(); JTextField serverAddress = new JTextField(defaultServer); JTextField port = new JTextField(Integer.toString(defaultPort)); final JComponent[] inputs = new JComponent[]{new JLabel("Username"), uname, new JLabel("Password"), passwd, new JLabel("Server Address"), serverAddress, new JLabel("Server Port"), port}; int var = JOptionPane.showConfirmDialog(parent, inputs, "Enter Connection Details", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (var != 0) { return; } .... </code></pre> <p>This creates a dialog box that prompts for some details to connect to a server. What I'd like is to make the password field the default selected. That is, the cursor is there by default so you can start typing it as soon as the pane appears, as opposed to having to select the password box first - By default, the OK button has focus.</p> <p>I've tried with passwd.requestFocusInWindow() but it doesn't work (because I think that the box has to be visible before calling that for it to work). I also tried overriding passwd's requestFocus method with various content, but it didn't fly either (probably because it's not getting called anyway....)</p> <p>Note: I know that some of the other JOptionPane methods have default value parameters, but they have issues laying out the input boxes, so they're no good to me.</p> <p>Anyone got any ideas? It's not a deal breaker, so I won't be too upset if it can't be done easily.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload