• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDialog- Multiple inputs

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to have a dialog box which has 5 textbox's and 2 combo. I need to get these values into my main frame. Can anybody help me out

Thanks
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to create a class with one instance variable for each value you want to return (7 in your case). Create the form and add "Accept" and "Cancel" buttons. When the user chooses "Accept", then transfer the values from the form (JTextField, JComboBox) to the instance variables and shut down the dialog form. When the user chooses "Cancel", then set the instance variables to null and shut down the dialog form. Make sure you have a "getter" method for each of the instance variables.

The calling class will instantiate and show the dialog [make sure it is modal]. Then simply call the seven "getter" methods to get the values from the dialog.

Here's a very simple class that returns a single value.

The constructor forces the dialog to be modal, meaning that the calling frame will be blocked until the user chooses ACCEPT or CANCEL, which is what you want. I like to leave out the "setVisible(true)" method call so the calling object can decide when to show the dialog.

The calling method would include these lines:

If the return value is "null", then you know the user selected "Cancel"; otherwise you'll get back the value they entered.

There are other ways of doing this, but this should help get you started.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
prav ford
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys. You solved my problem.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting this code. I had the same problem and this helped a lot.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic