Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

JTable and Fix Column Width/Size

 
Ranch Hand
Posts: 156
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");
 
Honk if you love justice! And honk twice for tiny ads!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic