Align the values of the cells in JTable?

后端 未结 7 841
闹比i
闹比i 2020-12-18 18:28

I\'m not aware of how to align the values of cells in JTable.

For Ex,The Jtable shows, Name Salary Mr.X 100000.50 XXXX 234.34

7条回答
  •  我在风中等你
    2020-12-18 19:01

    We need to make a small correction, the right way is DefaultTableCellRenderer.RIGHT

    DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
    rightRenderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
    tableExample.getColumn("Price").setCellRenderer( rightRenderer );
    

    Notice the difference with the original response of camickr, "Price" is the name of the column, change according to the case.

提交回复
热议问题