If I need to make my JOptionPane
always on the top of everything, this is the way I can do it:
JOptionPane optionPane = new JOptionPane();
JDialog dialog = optionPane.createDialog("My Dialog");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
But what about the input dialog of JOptionPane
?
Can we do similar thing to make sure the below input dialog appear on top?
JOptionPane.showInputDialog(null,"My Input");
Please note my application is not a GUI one, so I cannot set the parent window.
Finally I found the solution by digging down the JOptionPane
class itself.
JOptionPane
has a method called setWantsInput()
which we need to set true
, to make it a input dialog.
Here is a working code:
JOptionPane optionPane = new JOptionPane("body of the dialog");
optionPane.setWantsInput(true); //this is what I added
JDialog dialog = optionPane.createDialog("Title Of the Dialog");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
dialog.dispose();
System.out.println(optionPane.getInputValue());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With