Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resizing JFrame

 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok
 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you calling frame.setVisible(true)?
 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from the same methind itself, I am calling setVisible(true);
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> This is what I have done:

I can't compile/run the code, so I can't see what you're doing
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic