tags:

views:

32

answers:

2

I'm using a FlowLayout JPanel. The panel looks ugly when it's children components height are different. I'm looking for a solution to make them top-align (similar to valign="top" with table cell in HTML). Sorry for my bad English and hope someone can come up with a brilliant idea.

Thank you

A: 

Someone else has wished for this, in the form of a bug-report (which also lists a workaround).

Have a look at

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4295966

aioobe
Oh. I think I will follow the workaround. Thank you!
mrpaint
A: 

You should be able to use a BoxLayout. It supports vertical alignment. The only problem is you need to manually insert horizontal strut components.

Or you could try using the Relative Layout. In your case you would use:

RelativeLayout rl = new RelativeLayout(RelativeLayout.X_AXIS, 5);
rl.setBorderGap(5);
rl.setAlignment(RelativeLayout.LEADING);
JPanel panel = new JPanel( rl );
panel.add(...);
camickr
Sure I tried the vertical alignment but it didn't work :(
mrpaint
What doesn't work? I gave you two suggestions and both work. Did you read the Swing tutorial on "How to Use Box Layout"? If you need more help post your SSCCE: http://sscce.org
camickr
Finally, I extended the FlowLayout to make it work as I want and it's kinda cool now: only expand the width :D Thank you very much
mrpaint