Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Setting size of JTable columns

843804Jun 3 2005 — edited Dec 7 2005
Hi everybody,

Can anyone help me ?
How can I set a column widths of a JTable, but also allow the user to resize them ?

I tried with a code like
TableColumnModel tableColumnModel = table.getColumnModel();
        
for (int i=0; i < columnsSizes.length; i++) {
   if (columnsSizes[i] > 0) {
        tableColumnModel.getColumn(i).setPreferredWidth(preferedSizeArray);
}
}


But it doesn't work :(

When i do [ define the minWidth and maxWidth ]
TableColumnModel tableColumnModel = table.getColumnModel();

for (int i=0; i < columnsSizes.length; i++) {
    if (columnsSizes[i] > 0) {
        tableColumnModel.getColumn(i).setMinWidth(preferedSizeArray);
tableColumnModel.getColumn(i).setMaxWidth(preferedSizeArray[i]);
}
}



Columns's sizes are exactly what i want but ... the colums are no more resizable.

So,
if anyone can help me and tell me how can i set a predefined size for some colums and also allow the user to resize them ... that would be kind from him.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 4 2006
Added on Jun 3 2005
28 comments
463 views