• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

showInputDialog

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 80767
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 80767
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22854
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic