• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable and Fix Column Width/Size

 
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic