• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to return 2 values for a JDialog  RSS feed

 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the samples I found use JOptionPane to return a single value.
I am looking to return two values from two Text fields.
Any recommendations?
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can still use JOptionPane, but it requires a bit more work.
The trick is the message argument to several of the static methods. Most people only use Strings, but the Javadoc specifies what you can use. The trick here is the second in the list - Component. In other words, you can create a JPanel, add some content to it, then use the panel as the message:
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I may already had a solution.
One piece I was missing was setting the JDialog to be modal.
By default, control was being passed back and I was never getting my values.
Once it was created as modal, now the code appears to wait so then I can gather my info.
Just a minor detail missed.
Will post back with confirmation soon.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!