I have a program that uses 2-3 JFrame objects at the same time and adds components during runtime. I need one JFrame to send a message to the others and get them to repaint themselves. I'm fairly knew to java so please forgive me if I'm being an idiot and missing something simple.
Asked
Active
Viewed 193 times
0

mKorbel
- 109,525
- 20
- 134
- 319

Philbert McPleb
- 325
- 1
- 3
- 8
-
1I think you should add the important parts of the code. With this question, I can only say: Iterate over your collection (or however you keep track of your frames that you want to repaint) of `JFrame`s and call `repaint()` – Martin Thoma Feb 25 '13 at 21:34
-
1Have you tried the validate method? What have you tried so far? – Aaron Kurtzhals Feb 25 '13 at 21:37
-
1Each component should be responsible for its own repaint(). So if you call a method from frame 1 to frame 2 (let's sat `notifyMessage(String)`, in the `notifyMessage(String)` you should call `repaint()`. This properly separates responsibility. Read also about [Multiple JFrame good/bad practice?](http://stackoverflow.com/q/9554636/928711) – Guillaume Polet Feb 25 '13 at 21:56
-
Swing components repaint() themselves automatically. So you don't need to call repaint() or validate() or any method like that. You just need to update a component on the other dialog (don't use a JFrame) when the message is recieved and it will repaint itself. – camickr Feb 25 '13 at 22:03
-
I have the first frame repainting ok, but only after the user selects a refresh option from the menu. I had started working on a class to keep track of the frames but it looks like I might do better after reading up on layout managers and internal frames. – Philbert McPleb Feb 25 '13 at 22:43
1 Answers
4
Instead of multiple frames, use a single frame and as many modeless dialogs as needed. You can use a PropertyChangeListener
to ensure that updates in one container are propagated to another, as shown here and here.