How to left or right justify a column header in a JTable
I searched and couldn't find an answer for this. By default column headers in a JTab开发者_JAVA百科le are centered. How do I make certain column headers left or right justified instead?
TIA
TableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(SwingConstants.RIGHT);
table.getColumn(id).setHeaderRenderer(renderer);
Or, if you don't have the column names available:
table.getColumnModel().getColumn(index).setHeaderRenderer(renderer);
精彩评论