Nyx
Nyx

Reputation: 1374

Changing focus (JTextArea and JOptionPane)

In Swing, I am able to prompt the user for input using JOptionPane. The only problem this presents is the fact that the user can't change focus between the input box and the frame/content within it.

Is there any parameter I can put in to make it so that the focus is always on the frame. As a note, I have already tried requestFocus().

Thank you in advance.

Upvotes: 0

Views: 272

Answers (2)

xyz
xyz

Reputation: 201

The JOptionPane dialog is always modal. U can check this:

Can I use a Java JOptionPane in a non-modal way?

in order to bypass this behaviour.

Upvotes: 4

JB Nizet
JB Nizet

Reputation: 691735

The idea of JOptionPane is to show a modal dialog, which asks for confirmation or option, and to continue once the user has chosen an option. Without the chosen option, the program can't continue.

If you would like a non-modal dialog, then you'll need to construct it yourself, using JDialog.

Upvotes: 1

Related Questions