Author
Resizing JFrame
Neh Agarwal
Greenhorn
Joined: Feb 27, 2009
Posts: 24
Hi,
I have a JFrame which user can resize by clicking on the arrow on the corner. In that Frame I have added a button in the center using
buttonbox.add(Box.createHorizontalStrut((frame.getWidth()/2)-40));
when the user clicks on maximize or restore I am doing the same as above, but when the user resizes the frame by dragging the arrow, how do I make sure that the button is still in the center of the Frame?
Please Help!
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted Mar 06, 2009 03:42:14
0
a recent thread
http://www.coderanch.com/t/433817/Swing-AWT-SWT-JFace/java/jpanel-position;jsessionid=5EF60097F13D11740241378862CBA164
Neh Agarwal
Greenhorn
Joined: Feb 27, 2009
Posts: 24
Doesn't work that way,
I am confused, as how should I go about it,
it works fine when user clicks on max n min button but when resizes by dragging, it does not work
Can you please help!
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted Mar 06, 2009 04:07:04
0
works fine for me.
post a sample program showing it now working (just a frame with the layout set, and the button)
Neh Agarwal
Greenhorn
Joined: Feb 27, 2009
Posts: 24
ok
Neh Agarwal
Greenhorn
Joined: Feb 27, 2009
Posts: 24
This is what I have done:
int p=frame.getwidth();
buttonBox.add(Box.createHorizontalStrut((p/2)-40);
buttonBox.add(closeButton);
buttonPanel.add(buttonBox);
frame.getContentPane().add(buttonPanel,new GridBagConstraints ());
I don't know where did I mess up, but the frame is not launching at all
Please Help!
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
Where are you calling frame.setVisible(true)?
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Neh Agarwal
Greenhorn
Joined: Feb 27, 2009
Posts: 24
from the same methind itself, I am calling setVisible(true);
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted Mar 06, 2009 12:05:15
0
> This is what I have done:
I can't compile/run the code, so I can't see what you're doing
subject: Resizing JFrame