Align the values of the cells in JTable?

后端 未结 7 853
闹比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 18:48

    I have got a method that aligns a column in a table to the right:

    private void alignRight(JTable table, int column) {
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        table.getColumnModel().getColumn(column).setCellRenderer(rightRenderer);
    }
    

提交回复
热议问题