aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Setting column width in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting column width in JTable" Watch "Setting column width in JTable" New topic
Author

Setting column width in JTable

Raja Kannappan
Ranch Hand

Joined: May 08, 2002
Posts: 83
I've five columns in my JTable. Currently all of them are of same width. I want to set my first column to be of less width than the other four columns. How do I set it?
I only see a method called setRowHeight() in JTable but there is no method to set a column width.
Thanks,
- Raja.


SCJP
Jeremy Maddera
Greenhorn

Joined: May 02, 2002
Posts: 16
A possible solution to your issue is use a TableColumnModel this allows you to set the width of each column.
The Constructor for TableColumn allows you to set the width....

you also need the set the setAutoResizeMode on the Table object.
Raja Kannappan
Ranch Hand

Joined: May 08, 2002
Posts: 83
I'll try that.
Thanks,
- Raja.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
you don't need to create the table columns yourself:
Raja Kannappan
Ranch Hand

Joined: May 08, 2002
Posts: 83
myTable.getColumnModel().getColumn(0).setMaxWidth(int);
This one worked fine.
Thanks a lot!!!
- Raja.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting column width in JTable