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-27-2008, 08:03 PM
Member
 
Join Date: Jul 2007
Posts: 5
aleplgr is on a distinguished road
BorderFactory to set position?
Hi! I defined a BoxLayout JPanel because I need to show in this order:
a checkbox
a textfield
another checkbox
another texfield

and this works fine:

JPanel jPanelBoEx = new JPanel();
jPanelVars.add(jPanelBoEx, BorderLayout.LINE_START);
jPanelBoEx.setLayout(new BoxLayout(jPanelBoEx, BoxLayout.PAGE_AXIS));

jPanelBoEx.add(jchkbox1);
jPanelBoEx.add(jTextField1);
jPanelBoEx.add(jchkbox2);
jPanelBoEx.add(jTextField2);

But I need not to show them in the center, they must be shifted some position to the right so I use this:

jPanelBoEx.setBorder(BorderFactory.createEmptyBord er(0, 160, 0, 0));
To shift the four of them to the right, but I need the two labels to be more to the right than the 2 checkboxes..

How could I do that?
Thanks in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-29-2008, 03:39 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { JComponent[] comps = { new JCheckBox("CheckBox 1"), new JTextField(12), new JCheckBox("CheckBox 2"), new JTextField(12) }; JPanel jPanelVars = new JPanel(new BorderLayout()); JPanel jPanelBoEx = new JPanel(); jPanelBoEx.setBorder(BorderFactory.createEmptyBorder(0, 160, 0, 0)); jPanelVars.add(jPanelBoEx, BorderLayout.LINE_START); jPanelBoEx.setLayout(new BoxLayout(jPanelBoEx, BoxLayout.PAGE_AXIS)); for(int j = 0; j < comps.length; j++) { adjustAlignment(comps[j]); if(j % 2 == 0) { AbstractButton button = (AbstractButton)comps[j]; String text = button.getText(); button.setText(""); JLabel label = new JLabel(text); //adjustAlignment(label); Box box = Box.createHorizontalBox(); adjustAlignment(box); box.add(button); box.add(box.createHorizontalGlue()); box.add(label); if(j == 2) box.add(box.createHorizontalGlue()); jPanelBoEx.add(box); } else { jPanelBoEx.add(comps[j]); } } JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(jPanelVars); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private static void adjustAlignment(JComponent c) { String name = c.getClass().getName(); name = name.substring(name.lastIndexOf(".")+1); System.out.printf("%10s alignmentX = %.3f alignmentY = %.3f%n", name, c.getAlignmentX(), c.getAlignmentY()); float left = Component.LEFT_ALIGNMENT; float center = Component.CENTER_ALIGNMENT; c.setAlignmentX(left); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-30-2008, 01:46 PM
Member
 
Join Date: Jul 2007
Posts: 5
aleplgr is on a distinguished road
THANKS!!! great!!!
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
[SOLVED] How to make a JDialog scrolling from one position to the other. Eranga AWT / Swing 1 03-28-2008 11:26 AM
How to get the position of character in TextArea loganathan.lakshmanan JavaServer Pages (JSP) and JSTL 1 01-19-2008 01:06 AM
Help with position in java fernando New To Java 1 07-31-2007 08:54 PM
Use the mouse position susan Java Applets 1 07-29-2007 12:10 AM
JAVA Architect Position - Robert Half Technology pegitha Jobs Offered 0 05-18-2007 09:40 PM


All times are GMT +3. The time now is 02:16 AM.


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