Reputation: 578
I have a table like this image, That doesn't contain any data
So i want remove spaces after Send column, And i'am using
table.getColumnModel().getColumn(0).setPreferredWidth(5); //first column size
System.out.println(table.getColumnModel().getColumn(0).getPreferredWidth());
But it prints 15
!!
if i set the setPreferredWidth
to a number that be greater than 15
it affects the column
but if i set the setPreferredWidth
to a number that be smaller than 15
it doesn't affect the column, and it takes 15
by default
how can i solve it?
Upvotes: 1
Views: 197
Reputation: 27003
Use setMaxWidth(int)
to define not only prefered size but also max one, in your case
table.getColumnModel().getColumn(0).setPreferredWidth(5);
table.getColumnModel().getColumn(0).setMaxWidth(5);
System.out.println(table.getColumnModel().getColumn(0).getPreferredWidth());
OUTPUT:
5
Upvotes: 1