Results 1 to 7 of 7
Thread: Component align
- 05-22-2012, 06:15 PM #1
Senior Member
- Join Date
- Aug 2011
- Posts
- 248
- Rep Power
- 2
-
Re: Component align
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?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.
- 05-22-2012, 06:50 PM #3
Senior Member
- Join Date
- Aug 2011
- Posts
- 248
- Rep Power
- 2
Re: Component align
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!
-
Re: Component align
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.
- 05-22-2012, 07:03 PM #5
Senior Member
- Join Date
- Aug 2011
- Posts
- 248
- Rep Power
- 2
Re: Component align
Thank you so much!
-
Re: Component align
You're quite welcome!
- 05-23-2012, 06:43 AM #7
Similar Threads
-
How to align in java
By deemu in forum New To JavaReplies: 2Last Post: 02-06-2012, 08:50 PM -
Align Row to Right in JTable
By shomid in forum AWT / SwingReplies: 2Last Post: 11-25-2011, 10:23 PM -
Align left
By britto_bicsjohn in forum AWT / SwingReplies: 2Last Post: 09-09-2009, 04:05 AM -
How to align the output on console?
By sfe23 in forum New To JavaReplies: 5Last Post: 03-30-2009, 03:28 AM -
JTextArea - text align
By bradder in forum AWT / SwingReplies: 1Last Post: 11-29-2007, 07:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks