I am just beginning Java programming tonight (although I am a long time C++ code
ID: 3638602 • Letter: I
Question
I am just beginning Java programming tonight (although I am a long time C++ coder).I am experimenting with the JOptionPane.showInputDialog() function to gather user input.
However, it keeps setting the z-order of the input dialog underneath my IDE, with no notification on the start menu that a dialog is even there.
Is there any way to set options for it to appear at the top of the z-order, or perhaps even system modally?
Also, is there any way to limit the types of characters that can be entered into the text box of the input dialog, such as numeric types only?
Thanks for the help
Explanation / Answer
JOptionPane dialogs are always modal. There is no issue here. You will find your input dialog positioned in the center of the underlying JFrame (this), if you use it like this: String myInput = JOptionPane.showInputDialog(this, "myPrompt"); You will find it positioned in the center of your screen if you call it this way: String myInput = JOptionPane.showInputDialog("myPrompt"); In both cases the dialog is modal by default. In order to format and control the JTextField for your input, you should create your own JDialog, which is fairly easy and use JFormattedTextField inside with whatever restrictions you need.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.