File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and Fix Column Width/Size

 
Anand Karia
Ranch Hand
Posts: 156
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

How do i fix the column size according to my need.

Column 1 = 200
Column 2 = 200
Column 3 = 200
Column 4 = 0

I have a Method that set column name like this:

 
Kriti Garg
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
u can alter ur column width like this

....Code......
where jTbl is ur JTabel object

TableColumn hdr = jTbl.getTableHeader().getColumnModel().getColumn(
0);
hdr.setPreferredWidth(0);
hdr.setMaxWidth(0);
hdr.setMinWidth(0);
hdr.setWidth(0);
TableColumnModel cModel = jTbl.getColumnModel();
cModel.getColumn(0).setMaxWidth(0);
cModel.getColumn(0).setMinWidth(0);
cModel.getColumn(0).setWidth(0);
cModel.getColumn(0).setPreferredWidth(0);

....ur u an also get column by using column name from column model and then alter it

int index = jTbl.getColumnModel().getColumnIndex(
"Ur cloumn name");
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic