Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

showInputDialog  RSS feed

 
Brian Lemieux
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the code to make an Input Dialog box with multiple input boxes?

I want to get input into 4 input boxes found on an Input Dialog box and
capture those into their own variables and then pass then into an object.

I just need the code to create an Input Dialog with more than one input box for starters and from there I think I can get it.

 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds more like something for the Swing forum, so I shall move you.

You will have to go through the JOptionPane class, but I can't remember any methods which take 4 inputs simultaneously. You can call showInputDialog 4 times; that is quite easy.
By the way: If you are not using a Swing GUI you will probably need to pass "null" for the "parent" argument (usually the 1st argument). Then the input dialogue box will appear in the middle of your screen, (and might hide behind any other windows there!)
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you go to the API you find this link to the Java Tutorials, which will probably be very useful to you.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put 4 textfields on a JPanel
add the panel to an optionPane (message or confirm), as the 'object' arguement

when the optionPne closes you extract the values from the 4 textfields
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
showConfirmDialog will be better than showMessageDialog because you want to know if the user presses OK or not. Other than that Michael is right: just pass the JPanel as the message object.
 
Brian Cole
Author
Ranch Hand
Posts: 937
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
put 4 textfields on a JPanel
add the panel to an optionPane (message or confirm), as the 'object' arguement

when the optionPne closes you extract the values from the 4 textfields


Mr. Dunn is correct, and his way is probably best because you can control the layout of the panel, but you can also simply pass an array of text fields to JOptionPane.

You can even interleave Strings in the array. For example:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!