Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
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
Forum:
Swing / AWT / SWT
Resizing JFrame
Neh Agarwal
Greenhorn
Posts: 24
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 4632
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
a recent
thread
https://coderanch.com/t/433817/Swing-AWT-SWT-JFace/java/jpanel-position;jsessionid=5EF60097F13D11740241378862CBA164
Neh Agarwal
Greenhorn
Posts: 24
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ok
Neh Agarwal
Greenhorn
Posts: 24
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 22815
132
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Where are you calling frame.setVisible(true)?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Neh Agarwal
Greenhorn
Posts: 24
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
from the same methind itself, I am calling setVisible(true);
Michael Dunn
Ranch Hand
Posts: 4632
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
> 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
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
minimise to systray
How to restrict multiple Frames of the same class being opened by user?
How to close this window?
KeyListener
How to set value to JFrame from JInternalFrame
More...