• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tying two JFrames together

 
Bhiku Mhatre
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Any ideas about how to tie to separate JFrames together? (If people have used a popular MP3 player such as WinAmp, they would know what I am saying). I want to have two frames 'stuck' to each other, as in, if one frame is moved, the other moves with it as if the whole thing is a single frame. Something like this:
---------
|Frame 1|
---------
|Frame 2|
---------
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could do a WindowListener on the JFrames but I don't believe you can capture the drag event of the window from the WindowListener. You would also probably have to create a MouseListener and listen for the mousePressed and/or the mouseDragged events on the JFrame and adjust your other frame accordingly inside these methods. It's easy to move 2 frames together once you get that far though. Just need to get the x and y of the frames and move them accordingly.
Have you tried anything yet?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ComponentListener would also be very important...
[ July 31, 2002: Message edited by: Nathan Pruett ]
 
Bhiku Mhatre
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No..haven't tried anything yet. Was looking for some info before I try something out.. Looks like this is quite a non-trivial thing?
And yeah, I guess it's just not moving, If I close/minimize/maximize Frame 1 ,Frame 2 should also do the same thing..

Originally posted by Gregg Bolinger:
Well, you could do a WindowListener on the JFrames but I don't believe you can capture the drag event of the window from the WindowListener. You would also probably have to create a MouseListener and listen for the mousePressed and/or the mouseDragged events on the JFrame and adjust your other frame accordingly inside these methods. It's easy to move 2 frames together once you get that far though. Just need to get the x and y of the frames and move them accordingly.
Have you tried anything yet?

[ July 31, 2002: Message edited by: Bhiku Mhatre ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key thing here is Listeners. Once you are "Listening" for the proper events to happen, everything else is just an event or an action. Cause and Effect if you will. Try out some code, and if you get stumped, show us where your problem is and we can help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!