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 01-20-2008, 06:22 PM
Member
 
Join Date: Jan 2008
Posts: 3
Mark_Petrov is on a distinguished road
Having Trouble Aligning JLabels
Hello, I am fairly new to working with GUI. I have created a small test program because I am having trouble aligning JLabels in one of the programs I am currently working on (a Resume Maker). Here is the test program:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Test implements ActionListener{
JFrame frame;
JPanel contentPane;
JLabel p1, p2, p3;

public Test(){
frame = new JFrame("Test Label Alignment");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

contentPane = new JPanel();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
contentPane.setBorder(BorderFactory.createEmptyBor der(10,10,10,10));

p1 = new JLabel("eeeeee413");
p1.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
contentPane.add(p1);

p2 = new JLabel("yyyyy2");
p2.setAlignmentX(JLabel.LEFT_ALIGNMENT);
contentPane.add(p2);

p3 = new JLabel("3333333331");
p3.setAlignmentX(JLabel.LEFT_ALIGNMENT);
contentPane.add(p3);

frame.setContentPane(contentPane);

frame.pack();
frame.setVisible(true);
}

public void actionPerformed(ActionEvent event){
String eventName = event.getActionCommand();
}

private static void runGUI(){
JFrame.setDefaultLookAndFeelDecorated(true);

Test myGrades = new Test();
}

public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run(){
runGUI();
}
});
}
}

As you can see, I am trying to make "eeeeee413" aligned on the right of the JFrame, and "yyyyy2" and "3333333331" both aligned on the left of the JFrame.

The actual output shows "eeeeee413" aligned on the left of the JFrame, and "yyyyy2" and "3333333331" both aligned on the right of the JFrame.

Any help would be greatly appreciated
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
Compile Trouble adelgado0723 New To Java 5 04-21-2008 03:02 AM
trouble with program jimJohnson New To Java 1 04-03-2008 10:29 AM
problem with JLabels geork New To Java 3 01-31-2008 03:30 PM
Aligning Labels Java Tip Java Tips 0 01-02-2008 07:26 PM
Having trouble with array ice22 New To Java 3 11-13-2007 04:06 AM


All times are GMT +3. The time now is 04:42 AM.


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