Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Right Alignment in JTable Column

Tags:

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?

like image 468
Arivu2020 Avatar asked Aug 12 '10 11:08

Arivu2020


People also ask

Which of the following methods would you use to set a column width in JTable?

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.

How do I sort a row in JTable?

We can sort a JTable in a particular column by using the method setAutoCreateRowSorter() and set to true of JTable class.


1 Answers

DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); table.getColumnModel().getColumn(4).setCellRenderer(rightRenderer); 
like image 125
sathya Avatar answered Oct 06 '22 17:10

sathya