#Linking two frames in Java Swing; one event in the first frame triggers the same event in the second

1 messages · Page 1 of 1 (latest)

half urchin
#

Basically I'm trying to achieve what I wrote in the title
I have a JFrame, and a Dialog, but I want to connect them.
So for example, minimizing the JFrame also minimizes the dialog, moving etc.

I managed to get it to work using addComponentListener using the anonymous inner class and inside the implemented methods I wrote dialog.setLocationRelativeTo(frame).
this one worked, moving the frame moves the dialog.
But the ComponentListener interface doesn't have any methods for minimizing. so it just works for moving.
Now I need to get it to work for minimizing

I found this answer online

Toolkit.getDefaultToolkit().getSystemEventQueue().
        postEvent(new WindowEvent(dialog, WindowEvent.WINDOW_STATE_CHANGED));

I tried inside an anonymous WindowListener class for different values of WindowEvent.CONSTANT but it didn't work

sturdy groveBOT
#

<@&987246487241105418> please have a look, thanks.

sturdy groveBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

half urchin
#

I also found an answer that says I need to implement an observer pattern but this sounds like a common problem and I don't want to bloat my project when a solution probably exists

#

found another answer that also doesn't work, it's frame.dispatchEvent but it also didn't work

half urchin
#

Nevermind.
I have decided not to waste anymore time on this an am looking for an alternative

half urchin
#

I decided to scrap everything and switch to card layout. might as well rewrite everything instead.
today I understood why everyone keeps saying Java is really not the go to for GUI design