从右到左排列JTable列

时间:2012-06-17 06:30:07

标签: java swing jtable

当我向JTable添加列时,默认情况下,它们是从左到右排列的 例如如果我按此顺序添加(从左到右):

col1,col2,col3 

我会得到:

+------+------+------+
| col1 | Col2 | Col3 |
+------+------+------+

但我想要这个:

+------+------+------+
| col3 | Col2 | Col1 |
+------+------+------+

如何制作一个从右到左排列列的JTable

2 个答案:

答案 0 :(得分:5)

setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)或applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)将完成这一操作。 有关进一步说明,请参阅java doc

setComponentOrientation

applyComponentOrientation

  

或者你可以反转列名数组的数组   行数据数组。

答案 1 :(得分:2)

我是通过在JTable上设置.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)来实现的。

由于

相关问题