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?
Just click on form and go to JFrame properties, then Code tab and check Generate Center .
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.
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.
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).
frame.setLocationRelativeTo( null );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With