I searched and couldn't find an answer for this. By default column headers in a JTable are centered. How do I make certain column headers left or right justified instead?
TIA
Right-click on the table cells. From popup menu, choose "Table Contents..". Uncheck the editable check box for the column you want to make it non-editable.
The JTable class is a part of Java Swing Package and is generally used to display or edit two-dimensional data that is having both rows and columns. It is similar to a spreadsheet. This arranges data in a tabular form.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With