I have a JTable, which will auto-adjust its column widths based on the data in the cells. And to make this work I have to turn auto resize off by calling table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
The table sits in a JPanel with certain width.
The problem is that with auto_resize_off, when initially there is no data in the table or when the data in the grid is not long enough, the table will not expand across the entire width of the JPanel. So there is an empty gap between the right-end of the table and the right edge of the JPanel.
So I tried to do table.setMinimumSize(new Dimension(MyJPanelWidth, whateverHeight)) to make the initial width of the table same as that of the JPanel. But it does not work! Nothing gets changed for the table width.
However, table.setPreferredSize will change the table width, but my table will not auto-expand its columns, which does not serve my purpose either.
So my question is -- how do I set the initial/minimum table width without impacting its ability to auto-adjust its columns based on data?