• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Resizing JFrame

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a recent thread

https://coderanch.com/t/433817/Swing-AWT-SWT-JFace/java/jpanel-position;jsessionid=5EF60097F13D11740241378862CBA164
 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok
 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you calling frame.setVisible(true)?
 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic