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

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.