• 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

Returning a value from a modal dialog?

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When my JFrame calls a modal dialog for the user to enter a date, I want to return that date to my calling JFrame and set a date field (JTextField) when the dialog exits.
How do you do this?
Thanks in advance for any ideas.
Mike.
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,
Here's what you need to do. Extend the JDialog class. You should have a private field called myDate, or whatever. Then you should have a set and get method for this field. The set method should be private, since I'm assuming that you would not want to make it possible for an outside class to modify this field. And the get method should be either protected or public, depending on which packages you want to have access to this dialog. When the dialog closes, you call the set method and set the date field internally, before calling dispose(). Since the dialog is modal, your calling class execution will stop and will wait on the JDialog to close. After the statement that calls the JDialog in your calling class, you call the get method from the JDialog and set your text field on the JFrame. Hope this helps!

Barry
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic