对齐细胞在JTable中的价值? [英] Align the values of the cells in JTable?

查看:88
本文介绍了对齐细胞在JTable中的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使单元格的值在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);

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

这篇关于对齐细胞在JTable中的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆