Question

Is it possible to update a JFrame with data from another JFrame? Like, i change data on the right JFrame, then the data on the left JFrame would automatically update?

Was it helpful?

Solution

  1. your GUI should not have more than one JFrame displaying.
  2. Your problem more generally is simply how to update the state of one object from another. Often calling setter methods should work. Sure this trivializes the question, but without further information from you, that's about the most we can tell you.
  3. When to do an update of the object may be a more difficult issue to tackle, and here using a observer pattern often is helpful. Examples of this include using ActionListeners or ChangeListeners or PropertyChangeListeners.

For help in greater depth, consider giving us greater depth on your question.


Edit
You state:

The other JFrame is in another class. If you click a JButton the JFrame in another class will popup and it will update the JLabel in there. the 2 jframes is not in the same class.

  • The second "JFrame" should be a JDialog, not a JFrame, and likely a modal dialog. This way you will know when the user has completed work on it, since when it is no longer visible, code flow will resume to the code that made the dialog visible.
  • Again, transferring information from one "class" to another (really this is from one object to another) is often done via setter methods.

If you're still confused, then please create a small compilable and runnable program that shows us your problem, an sscce.


Edit 2
For an example of just what I'm suggesting, please see my answers and code here:

OTHER TIPS

I don't know why you have two but you could create a super or extend the JFrame. There are also many various inheritance practices to use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top