File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTable and Fix Column Width/Size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and Fix Column Width/Size" Watch "JTable and Fix Column Width/Size" New topic

JTable and Fix Column Width/Size

Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

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:

Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
Kriti Garg
Ranch Hand

Joined: Sep 13, 2004
Posts: 50
u can alter ur column width like this

where jTbl is ur JTabel object

TableColumn hdr = jTbl.getTableHeader().getColumnModel().getColumn(
TableColumnModel cModel = jTbl.getColumnModel();

....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:
subject: JTable and Fix Column Width/Size
It's not a secret anymore!