I have a ScrollPane and JTable that should only have one row of data.
String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
String[][] data = {{"None","None","None","None","None","None","None"}};
JTable mTable = new JTable(data, daysOfWeek);
JScrollPane scrollPane = new JScrollPane(mTable);
mTable.setFillsViewportHeight(false);
I want the ScrollPane to fit around the borders of the table but at the moment the height of the Scrollpane takes up the entirety of the container, making it look really ugly. I don’t understand why, since I set mTable.setFillsViewportHeight(false).
Any help how to achieve a ScrollPane that doesn’t stretch beyond the size of the table would be welcome.
you can use
table.setPreferredScrollableViewportSize(table.getPreferredSize());edit