I tried putting a JFrame
into a JOptionPane
using the following code:
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(300, 75);
//frame.add(textField);
frame.setVisible(true);
frame.requestFocus();
String input = JOptionPane.showInputDialog(frame, "What is the number? ");
This works. However, when I click OK or Cancel in the option Pane I expected the frame to close as well. But it doesn't.
Therefore, I tried passing null
to the option pane instead of passing frame. This works too but when I do this the dialog does not appear (flashing on bottom of screen) as it does when I pass a frame object.
So basically is there a way to:
- Either automatically close the frame when option pane button is clicked?
- Or make an option pane flash (and be focused) just like a frame? (Using
.requestFocus
does not work for some reason)