Fixing the height of a swing component in a box layout

Good morning,

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

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

I've tried everything to fix the first height of the JTable but with no success.
I dedicate Box.createHorizontalBox () to each component of the above lines and then add them to Box.createVerticalBox ().
Instead of getting the first result, I end up with a layout where the JTable has an auto height, and I would prefer the first JTable to have a fixed height ...

Thanks for any answer,

Greetings

0


a source to share


3 answers


I found a solution and I shouldn't have annoyed you with such a silly problem:
For every horizontal box I created, I added a 10px horizontal column to show the fill view. The thoses struts were first on the lines and it was automatically accepted as a "height reference" for building a box layout, but I'm new to awt / swing layout, so I might be wrong in saying that.

I removed these posts and inserted a vertical frame containing 10px horizontal posts. He did the job.



Anyway, thanks for your time Marcus and Michael, I'll dive deeper into the sun tutorial when my boss gives me time to do it.

Greetings

+2


a source


You can change the line 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 size of the table you can update by calling



setPreferredSize(Dimension preferredSize)

      

You also need to decide what layout the shoul panel has. Have you set the layout?

0


a source


How about displaying the actual code?

It looks like you are using layout managers incorrectly. You should probably use a BorderLayout with an "auto" table at the CENTER position, and the rest in the second pane at the NORTH position, and the second with Boxlayout or FlowLayout.

Sun has a very good tutorial on using Layout Managers, which can probably help you.

0


a source







All Articles