wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Problem with Alignment in BoxLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with Alignment in BoxLayout" Watch "Problem with Alignment in BoxLayout" New topic
Author

Problem with Alignment in BoxLayout

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I have had this problem with a few apps, but just worked my around them. But I kind of need a solution to the problem now. I have a JDialog and I am using a BoxLayout with Y Alignment. I am adding JLabel, JTextField, JLabel, JTextField....
I need the JLabels to align to the left so I am using setAlignmentX(Component.LEFT_ALIGNMENT) but it is not moving the labels. Can someone look at my code and see if they can see what I am not seeing?
Thanks.


GenRocket - A Test Data Generation Platform
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

For your example, the best solution is to replace the BoxLayout with a new GridLayout( 0, 1 ). I think BoxLayout centers it's components, and I don't see a way to change this without extending the class. In this case the fix is easy, just use a 1 column GridLayout, otherwise you'd have to use GridBagLayout or something that lets you mess with the placement of individual components more.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I will probably go ahead and do that. However, the SWING tutorial says this should be possible.
Fixing Alignment Problems
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Alignment in BoxLayout
 
Similar Threads
regarding focus in swing
Box.createGlue() creates nothing
keyboard action of my JButton
Displaying certain items on a panel based on radio button selection.
i keep on seeing the console window and not the applet