• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing variables between JFrames  RSS feed

 
Randy Johnson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a JFrame to enter data into JTextFields. One field gives the user the ability to 'Look Up' valid entries in a second JFrame. The second JFrame displays that values, and the user select a value, to be returned to the calling method. When I instantiate and run the second JFrame, I return the selected value in the WindowClosing event. But I can't figure out how to make the calling method 'wait' for the closing event to load the variable. Once setVisible is executed, the calling method keeps running to the next statment? How can i make it wait?
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I don't know something about your project, but in most cases we use a JDialog to make inputs. This can be modal, so your main frame will wait for it. If you want, you can call it from the constructor of your JFrame. Once the user has been finished, you can ask your dialog class for the input values, then you can proceed to display your main frame.
 
Randy Johnson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rene Liebmann:
Ok, I don't know something about your project, but in most cases we use a JDialog to make inputs. This can be modal, so your main frame will wait for it. If you want, you can call it from the constructor of your JFrame. Once the user has been finished, you can ask your dialog class for the input values, then you can proceed to display your main frame.
 
Randy Johnson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Randy Johnson:
Sorry for the previous reply - operator error!
Thank you for the reply. I can see that in som e cases a JDialog may work. But in this case, the second is actually using JDBC to pull data from a table. The user can scroll through a result set, to select a specific row to return, so I don't think a dialog will be flexible enough.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JDialog is as flexible as you want it to be... in fact, about the only thing that really separates a JDialog from a JFrame is that a JDialog can be modal...
 
Randy Johnson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all for the advice! The JDialog lets me do exactly what I need!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!