Hi everyone,
I am learning to use the swing api and need some help on aligning my JComponents.
I have a JDialog window which consists of several JPanels using FlowLayout to put a JLabel and JTextField on the same horizontal axis. These JPanels are then added to another JPanel using BoxLayout with vertical alignment. My JLabels have varying lengths and the rows are centered horizontally in the window so the JTexFields don't line up properly. How can I align things so the JTextFields have perfect horizontal alignment and the JLabels are left justified?
Aligning JComponents
Started by ClemsonCS, Apr 12 2009 04:05 PM
3 replies to this topic
#1
Posted 12 April 2009 - 04:05 PM
|
|
|
#2
Posted 12 April 2009 - 04:15 PM
If it will take too much work to left justify the JLabels I could do with just right justifying the JPanels that make up the rows.
#3
Posted 12 April 2009 - 10:54 PM
Would be great if you didn't double post, lol.
Well you could use this while setting up your layout...
To position them wherever you want you will have to use.
y - the new y-coordinate of this component
width - the new width of this component
height - the new height of this component
Hope this will help you !
Also visit,
Component (Java 2 Platform SE v1.4.2)
So you can get a better grip of functions and usage
Well you could use this while setting up your layout...
setLayout(null);While having a layout set to null, you can place your JComponents wherever you want to in the panel/frame.
To position them wherever you want you will have to use.
setBounds(int x,int y,int width,int height)x - the new x-coordinate of this component
y - the new y-coordinate of this component
width - the new width of this component
height - the new height of this component
Hope this will help you !
Also visit,
Component (Java 2 Platform SE v1.4.2)
So you can get a better grip of functions and usage
#4
Posted 14 April 2009 - 10:05 PM
I found that I could just RIGHT align my JPanel with flowlayout but I found a use for that method else where in my code. thanks.


Sign In
Create Account


Back to top









