4
votes

I have a JTable with autoResizeMode set to AUTO_RESIZE_LAST_COLUMN. I have added it to a panel by creating a JScrollPane with the JTable as its child widget, and then adding the JScrollPane to the panel.

I would like to set the size of the JScrollPane viewport to that of the parent JPanel, and have the JTable resize its last column dynamically.

3
What did you try sofar ? what exaclty doesnt work ? SHow a simple example that actually runs and describe what isent working. - Peter
in Swing/AWT, the concept of "set size to .." is incorrect - locating/sizing is the job of the LayoutManager, which all behave differently. Developers choose one which produces the result they want to achieve :-) - kleopatra

3 Answers

4
votes

I think if you make the JPanel use GridLayout(1,1) and add the JScrollPane to it then you will get the desired result.

3
votes

JPanel have got implemented FlowLayout by defaut, you can place JScrollPane to the BorderLayout.CENTER

0
votes

The first answer on this link How to make a JTable fill entire available space? worked perfectly for me.

I did the following

myPanel = new JPanel(new GridLayout());
myJtable = new JTable(MyTableModel);
myPanel.add(new JScrollPane(myJtable));