tags:

views:

503

answers:

3

Good morning,

I am making a GUI thanks to javax.swing.Box class

Inside the panel:
JLabel
JTable with fixed height
JLabel
JTable with automatic height

I tried everything to fix the first JTable height but without any success.
I dedicate a Box.createHorizontalBox() for each component of the above rows and then I add them to the Box.createVerticalBox().
Instead of getting the first result I get a layout where both JTable has a automatic height, and I'd prefered the first JTable to have a fixed height...

Thanks for any answer,

Cheers

A: 

You can change to row height for example by calling

TableColumn column = table.getColumnModel().getColumn(0);
    column.setPreferredWidth(150);
    //set all rows height 
    table.setRowHeight(20);
    //set specific row height
    table.setRowHeight(2,50);

The table size you can update by calling

setPreferredSize(Dimension preferredSize)

You also have to decide, which layout the panel shoul have. Did you set a layout?

Markus Lausberg
A: 

How about showing us the actual code?

It sounds like you're not using layout managers correctly. You should probably use a BorderLayout with the "automatic" table in its CENTER position and the rest inside a second panel in the NORTH position, with that second panel using either a Boxlayout or a FlowLayout.

Sun has a very good tutorial on using Layout managers that can probably help you a lot.

Michael Borgwardt
+1  A: 

I found a solution and I shouldn't have annoyed you with such a silly problem:
For each horizontal box I created, I added an horizontal strut of 10 pixels to show a kind of padding. Thoses struts were the firsts in the rows and it was automaticly taken as the "height reference" for the box layout building, but I'm new to awt/swing layout so I may be mistaking saying that.

I removed those struts and inserted a vertical box which contained a horizontal struts of 10 pixels. It did the job.

Anyway, thanks for your time Markus & Michael, I'll dive deeper in sun's tutorial when my boss will let me the time to do so

Cheers