I have written a program that reads a csv file and put it into a jTable that will be displayed in a seperate jFrame as a preview. Everything works fine but I would like to use the optimal size for the jTable in the preview frame.
So how to do it? Because if for example I choose another font for the text, the column would be wider or smaller? Is there a method to get the text-length in pixels (size)?`
The class looks like this:
Thanks
JTableimplementsScrollable, and thepreferredViewportSizeis arbitrarily set toDimension(450, 400). That size is obtained by wrapping the table in aJScrollPaneand invokingpack()on the enclosingWindow. Mindful of some important caveats, you can usesetPreferredScrollableViewportSize()to change the default size. A multiple ofgetRowHeight()may be a suitable choice for the height.