• Post Reply Bookmark Topic Watch Topic
  • New Topic

Set JFrame relative to another JFrame  RSS feed

 
Maroun Marounn
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two JFrame. I set the second JFrame to be located in the center of the first JFrame.
Now I want them to always show/hide together. I mean, if the smallest JFrame minimized then the bigger JFrame will be minimized too, and if I show the small JFrame it'll be kind of "sticked" to the other JFrame.

How can I achieve this?

Thanks.
 
Randall Twede
Ranch Hand
Posts: 4690
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can help with part of that. use the setLocationRelativeTo(Component c) method to make the small one "stick to" the main one. can't say i have actually tried it though, i like setLocationRelatveTo(null) which places it in the center of the screen.
 
Maroun Marounn
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:i can help with part of that. use the setLocationRelativeTo(Component c) method to make the small one "stick to" the main one. can't say i have actually tried it though, i like setLocationRelatveTo(null) which places it in the center of the screen.


I tried that, this sets the location of the JFrame, but it doesn't "stick" it to the Component.
 
Randall Twede
Ranch Hand
Posts: 4690
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see what you mean. if i close the main one they both close, but minimizing one does not affect the other. i,m sure there is a way. just be patient and someone more knowledgeable than me will know how. maybe
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you click on Bigger JFrame, the small JFrame will be hidden. Therefore, it is good to use a JDialog as the smaller Window. And the things you want can easily be done using JDialog..
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having multiple frames in one application is bad usability. As has been already suggested go for dialogs
More on dialogs here http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!