Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 3:38 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ]  Bookmark and Share
Author Message
 Post subject: arranging Jlabel & JTextFiled
PostPosted: Sat May 12, 2007 9:31 am 
Offline

Joined: Tue May 08, 2007 6:50 pm
Posts: 4
Hi, I am learning how to use group layout in Swing. For example I have these labels and textFileds.

JLabel nameLabel = new JLabel("Name");
JLabel streetLabel = new JLabel("Street");
JLabel suburbLabel = new JLabel("Suburb");
JLabel phoneLabel = new JLabel("Phone");
JLabel emailLabel = new JLabel("Email");

name = new JTextField(20);
street = new JTextField(40);
suburb = new JTextField(20);
phone = new JTextField(20);
email = new JTextField(20);
setFieldsEditable(false);

Now to arrange it using GroupLayout.SequentialGroup class as following part of code, the question is that I don't understand the concept to add the components horizontally and vertically. Could anybody give me some suggestions?

// Create a sequential group for the horizontal axis.
GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();

// The sequential group in turn contains two parallel groups.
// One parallel group contains the labels, the other the text fields.
hGroup.addGroup(layout.createParallelGroup().addComponent(nameLabel)
.addComponent(streetLabel).addComponent(suburbLabel).addComponent(
phoneLabel).addComponent(emailLabel));
hGroup.addGroup(layout.createParallelGroup().addComponent(name)
.addComponent(street).addComponent(suburb).addComponent(phone)
.addComponent(email));
layout.setHorizontalGroup(hGroup);

// Create a sequential group for the vertical axis.
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();

vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(nameLabel).addComponent(name));

vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(streetLabel).addComponent(street));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(suburbLabel).addComponent(suburb));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(phoneLabel).addComponent(phone));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(emailLabel).addComponent(email));
layout.setVerticalGroup(vGroup);


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley