wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and Fix Column Width/Size" Watch "JTable and Fix Column Width/Size" New topic
Author

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
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
 
subject: JTable and Fix Column Width/Size
 
Similar Threads
Jtable CellEditor
How to add rows to jTable dynamically?
jtable highlight cells (refresh issue)
Problem in setting column width..
sort(int[], int, int) in the type Arrays is not applicable for arguments (int[], Comparator<Object>)