I tryed few layouts to get a simple component to the middle of the screen and I always failed.
My single goal is to get it to the middle by X and Y.
How do I do that?
Printable View
I tryed few layouts to get a simple component to the middle of the screen and I always failed.
My single goal is to get it to the middle by X and Y.
How do I do that?
components are placed relative to their container, not the screen. Exactly what are you trying to do? Center a component in a container? Center a Window on the desktop (screen)? The details matter.
middle by X and Y?Quote:
My single goal is to get it to the middle by X and Y.
How do I do that?
Again, please clarify, again please tell the details.
I have a JFrame and a label.
I want the label to be in the middle of the JFrame.
The JFrame is set to full screen with no borders so I assume that the middle of the JFrame is the middle of the screen.
"By x and y" I mean that I want it to be centered x alignment and y alignment.
Thanks!
The easiest way I know to center a component in the container is to have the container user GridBagLayout, and add the component to the container without any GridBagConstraints. So for your situation, call on your JFrame, getContentPane().setLayout(new GridBagLayout()), and then add the JLabel to the JFrame.
Thank you so much!
You're quite welcome!
Moved from New to Java
db