Make jscrollpane (containing jtable) fill its container

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

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

+4
source share
3 answers

JPanel implemented by FlowLayou t defaut, you can place JScrollPane in BorderLayout.CENTER

+3
source

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

+4
source

First answer to this link How to make JTable fill all the free space? worked great for me.

I did the following

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

Source: https://habr.com/ru/post/1394955/


All Articles