Hi Guys, If any of you could help I would be grateful: I have an application with a fixed window size, within this I have a JTabbedPane, each tab contains a JScrollPane which contains a JTable. The tables can have different numbers of columns. I am trying to achieve a uniform look and this is where I am having problems. I set the columns to a minimum width. If there are few columns, less than the width of the JScrollPane, I would like the columns to resize to fill the scroll pane. This is acheivable by setting the auto resize mode to AUTO_RESIZE_ALL_COLUMNS. If there are many columns I would like a horizontal scroll bar, this is achieved by setting the auto resize mode to AUTO_RESIZE_OFF, however to achieve both automatically is the problem. You can achieve this effect by placing the table in a JPanel and adding the panel to the scroll pane but then you lose the column headings. I would settle for being able to detect the size of the viewport, then I could calculate the minimum column size * the number of columns and set the resize mode accordingly. However when I get the viewport associated with the scroll pane I canot get its size (I used viewport.getExtentSize()), it always comes back with a width and height of 0. Any ideas would be appreciated. Regards, Derek Drever
posted 12 years ago
Found a solution on another forum, just extend JTable and override the following method - works a treat.