Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center Swing Windows

I'm developing a Java Swing application. How can I make it so that when the program itself and any other windows open they come up in the center of the screen?

like image 909
Travis Avatar asked Jun 21 '10 03:06

Travis


People also ask

How do I center a JFrame?

Just click on form and go to JFrame properties, then Code tab and check Generate Center .

How do I center my screen in Java?

By default, a JFrame can be displayed at the top-left position of a screen. We can display the center position of JFrame using the setLocationRelativeTo() method of Window class.

What is setLocationRelativeTo?

setLocationRelativeTo(null); As the Javadoc for the setLocationRelativeTo method states: Sets the location of the window relative to the specified component. If the component is not currently showing, or c (the Component) is null, the window is centered on the screen.

What is JMenuBar?

JMenuBar is an implementation of menu bar . the JMenuBar contains one or more JMenu objects, when the JMenu objects are selected they display a popup showing one or more JMenuItems . JMenu basically represents a menu . It contains several JMenuItem Object . It may also contain JMenu Objects (or submenu).


1 Answers

frame.setLocationRelativeTo( null );
like image 75
camickr Avatar answered Sep 21 '22 13:09

camickr