JTable
implements Scrollable
, and the preferredViewportSize
is arbitrarily set to Dimension(450, 400)
. That size is obtained by wrapping the table in a JScrollPane
and invoking pack()
on the enclosing Window
. Mindful of some important caveats, you can use setPreferredScrollableViewportSize()
to change the default size. A multiple of getRowHeight()
may be a suitable choice for the height.
Optimal Jtable size java
Question
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
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow