• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable Centering Display

 
vinaya kumar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
How do i center a display of a column?
all the data in the column of the table
are left centered,how do i make it Centered
Thanks in Advance
vinaya
 
keerthi matta
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
Define ur own TableCellRenderer class
lets say it MyTableCellRenderer,
which extends DefaultTableCellRenderer and make ur table lets say yourTable,
call the method setCellRenderer

yourTable.setCellRenderer(Object.class,new MyTableCellRenderer());
,and in MyTableCellRenderer class ,u need to overwrite a method
public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected, boolean hasFocus,int row,int column)
in the method just define
setHorizontalTextPosition(SwingConstants.CENTER);
setHorizontalAlignment(SwingConstants.CENTER);
then the data in the column will be aligned Center
njoy coding
hope this solves ur problem
keerthi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!