• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set the alignment of each column in Jtable  RSS feed

 
adachi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a JTable and want to set the alignment of each column independently. Meanwhile, I want to set one of that columns cannot be edited.
I have get each column such like this:
javax.swing.table.TableColumn column1 =
GoodsTable.getColumnModel().getColumn(0);
Any one can help me??
Thanks
 
reddy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the code to st width of each column and if you don't want resizing and reordering you can use last two lines od code
jTable1.getColumnModel().getColumn(0).setPreferredWidth(10);
jTable1.getColumnModel().getColumn(1).setPreferredWidth(250);
jTable1.getTableHeader().setReorderingAllowed(false);
to disable reordering and resizing
jTable1.getTableHeader().setResizingAllowed(false);
to make a column non editable set isCellEditable to false
regards
reddy
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
adachi (and reddy),

Please re-register with a username that follows the JavaRanch Official UserName Conventions. Your username is required to be in the format "First Name" + space + "Last Name".

Thanks,

-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!