• Post Reply Bookmark Topic Watch Topic
  • New Topic

Table column Heading justification

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to left justify JTable column headers?

Thanks
 
Kriti Garg
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Barry,

u can justify ur aligment of header or data in columns

there r classes avaliable ,kindly read "TableCellRenderer"

make a class which extends JLabel and implements TableCellRenderer

......

jTabel.getTableHeader().setDefaultRenderer(new
MyTableCellRenderer());

.......

class MyTableCellRendererextends JLabel implements TableCellRenderer {
public MyTableCellRenderer() {
super();
setOpaque(true);
}

public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int
row,
int column) {

String s = (String) value;
setText(s);
setHorizontalAlignment(RIGHT);

setForeground(table.getForeground());
setBackground(table.getBackground());


return this;
}
}

Hope this will help u out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!