wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Resizing JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Resizing JFrame" Watch "Resizing JFrame" New topic
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
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
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: 19656
    
  18

Where are you calling frame.setVisible(true)?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
> This is what I have done:

I can't compile/run the code, so I can't see what you're doing
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resizing JFrame
 
Similar Threads
How to close this window?
How to set value to JFrame from JInternalFrame
How to restrict multiple Frames of the same class being opened by user?
minimise to systray
KeyListener