• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDialog- Multiple inputs

 
prav ford
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • 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.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
prav ford
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys. You solved my problem.
 
John Deal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting this code. I had the same problem and this helped a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic