Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-04-2008, 09:45 AM
Member
 
Join Date: May 2008
Posts: 29
adeeb is on a distinguished road
"Problem With GroupLayout", Please Help !
Hi,
i am having a problem with the code which i have written. It is not giving the desired output. i.e i wanted to place in first line a label and a text field and in second line also same a label and a text field. But i am getting all the four components in a line. Can any body give me the solution please. Here is my code.Please point where to modify it.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import static javax.swing.GroupLayout.Alignment.*;

public class exp5 extends JFrame
{
private Container c;
//private GroupLayout gl;

public exp5()
{
super("Experiment5");
c = getContentPane();
JPanel panel = new JPanel();
JLabel name = new JLabel("Name");
JLabel age = new JLabel("Age");
JTextField tf = new JTextField(20);
JTextField tf1 = new JTextField(10);
GroupLayout layout = new GroupLayout(panel);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createSequentialG roup().addComponent(name).addComponent(tf)
.addGroup(layout.createParallelGroup().addComponen t(age).addComponent(tf1))
);
layout.setVerticalGroup(layout.createParallelGroup ()
.addGroup(layout.createParallelGroup().addComponen t(name).addComponent(tf).addComponent(age))
.addComponent(tf1));

getContentPane().add(panel);
setSize(600,600);
setVisible(true);

}
public static void main(String args[])
{
exp5 exp = new exp5();
exp.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-04-2008, 11:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Jumble" or "Scramble" Program Shadow22202 Java Applets 8 04-30-2008 04:42 AM
"Displayed tab width" problem... Petike Eclipse 0 03-17-2008 10:39 PM
I have a problem with variable "i" silvia New To Java 2 08-08-2007 12:05 AM
Hwlp with "Open", "Save", "Save as..." trill New To Java 1 07-31-2007 08:53 AM
Problem with "GregorianCalendar" tola.ch2004 New To Java 2 07-12-2007 09:12 PM


All times are GMT +3. The time now is 01:20 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org