View Single Post
  #2 (permalink)  
Old 06-04-2008, 12:29 PM
Eranga's Avatar
Eranga Eranga is offline
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have to think about both horizontal as well as vertical alignments in the layout.

Code:
import javax.swing.*; import static javax.swing.GroupLayout.Alignment.*; /** * * @author Eranga Tennakoon */ public class GroupLayoutTest extends JFrame{ public GroupLayoutTest() { JLabel name = new JLabel("Name"); JLabel age = new JLabel("Age"); JTextField tf = new JTextField(20); JTextField tf1 = new JTextField(20); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING) .addComponent(name) .addComponent(age)) .addGroup(layout.createParallelGroup(LEADING) .addComponent(tf) .addComponent(tf1)) ); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE) .addComponent(name) .addComponent(tf)) .addGroup(layout.createParallelGroup(LEADING) .addComponent(age) .addComponent(tf1)) ); setTitle("GroupLayout"); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } public static void main(String[] args) { // TODO code application logic here java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GroupLayoutTest().setVisible(true); } }); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote