I am creating an application for a billing facility. I want the amount column to display with right alignment. How do I set the right alignment for a JTable column?
By default the width of a JTable is fixed, we can also change the width of each column by using table. getColumnModel(). getColumn(). setPreferredWidth() method of JTable class.
We can sort a JTable in a particular column by using the method setAutoCreateRowSorter() and set to true of JTable class.
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); table.getColumnModel().getColumn(4).setCellRenderer(rightRenderer);
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