• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Returning a value from a modal dialog?

Posts: 1757
  • Mark post as helpful
  • send pies
  • 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.
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic