对齐细胞在JTable中的价值?细胞、价值、JTable

由网友(霸气让你着迷)分享简介:我不知道如何使单元格的值在JTable中。I'm not aware of how to align the values of cells in JTable.有关防爆,JTable中显示,名称薪水X先生100000.50XXXX 234.34YYYY 1205.50 For Ex,The Jtable sho...

我不知道如何使单元格的值在JTable中。

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

有关防爆,JTable中显示,        名称薪水        X先生100000.50        XXXX 234.34        YYYY 1205.50

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

我想在下面的格式调整的工资。

I want to align the "Salaries" in the following format.

   Name      Salary
   Mr.X      100000.50
   XXXX         234.34
   YYYy        1205.50

如何调整与上述的JTable

How to align as above the JTable

推荐答案

有没有必要建立这样的自定义类,只是使用的默认渲染器:

There is no need to create a custom class for this, just use the default renderer:

DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
table.getColumnModel().getColumn(???).setCellRenderer(rightRenderer);

或者更好的办法是实际存储在表中双击值,然后适当的数字渲染器将被使用,一些渲染器会自动右对齐。然后,您可以使用表格式渲染。

阅读全文

相关推荐

最新文章