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
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
window position
chris barr
Ranch Hand
Posts: 37
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
when i create a new window i want it to appear in the center of the screen or at least not the upper left hand conner how do you set were it appears?
Martin Simons
Ranch Hand
Posts: 196
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is one of my favorite ways:
JFrame frame = (JFrame) new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Get the screen size GraphicsConfiguration gc = frame.getGraphicsConfiguration(); Rectangle bounds = gc.getBounds(); // Create and pack the Elements //.... code to create the panels etc frame.pack(); // Set the Location and Activate Dimension size = frame.getPreferredSize(); frame.setLocation((int) ((bounds.width / 2) - (size.getWidth() / 2)), (int) ((bounds.height / 2) - (size.getHeight() / 2))); frame.setVisible(true);
Michael Dunn
Ranch Hand
Posts: 4632
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
you could also try
frame.setLocationRelativeTo(null);
but must be called after the size of the frame is set
i.e. after setSize(...) or after pack()
chris barr
Ranch Hand
Posts: 37
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks .. that works perfectly.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Always centering frame through a BaseFrame overiding setVisible: dirty ?
Setting placement of JDialog
Tree and forms - like Windows Explorer. How to display several forms in the same screen location...
Dynamically positioning a window so it isn't in the way.
how to create small windows
More...