0

My main JFrame content panel which is card layout and I have added many (say panel1, panel2) panel as card. I would like to update UI panel1 when something changes in panel2.

How to update child (panel) of CardLayout in Swing?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Krishna Shrestha
  • 1,662
  • 14
  • 38

2 Answers2

2

The observer pattern, discussed here, is the key to this. In particular, both panels could listen to a common model, which would fire events to update each listening panel. Examples using PropertyChangeListener may be found here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

Maintain a reference to the target of what you want to change, and use some kind of callback function to detect the changes. Use the stored reference in the callback function. How you specifically implement this should be whatever makes most sense for your code... but what you are trying to do is a simple task.

parker.sikand
  • 1,371
  • 2
  • 15
  • 32