Dear All,

I have a problem, i need to align all components(JLabel,JTextField,etc) to right in the JPanel. Is there any layout method which can set the layout of the jpanel and then adding any jcomponent is aligned as the JPanel.

thanx in advance

8 Years
Discussion Span
Last Post by BestJewSinceJC

The GridBagLayout is possibly what you will need. However, it is possibly the most advanced of Java's standard layouts. It gives you full control over margins (Insets) which gives great control over alignment issues. A google search should provide plenty of examples of the use of this layout.


An easier way to do it might be to have a JPanel inside a JPanel. The outer JPanel would use a BorderLayout, and the JPanel that you add to that one would have a GridLayout with one column. The idea being that when you added the second JPanel to the first, you'd add it to BorderLayout.LINE_END. . then anything you added to that JPanel would show up on the right side.

This is my idea, however, I'm now working with swt not swing, so it might not work in swing. . I might be combining my knowledge of the two layout tools.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.