简体   繁体   English

Java:JTable添加和移动列

[英]Java: JTable adding and moving columns

im quite new in Java. 我在Java中相当新。 I want to add Columns in a JTable at a specified index. 我想在JTable中的指定索引处添加列。 For this i am using addColumn(..) and then move them with moveColumn(...), this works great at the first time, but when i add another column it kind of moves also the other(before added columns). 为此,我使用addColumn(..),然后使用moveColumn(...)将其移动,这在第一次使用时效果很好,但是当我添加另一列时,它也会移动另一列(在添加列之前)。

Do you have any suggestions? 你有什么建议吗?

this is the code i've written in the TableModel is: 这是我在TableModel中编写的代码是:

    public void addColumn(Object columnName, 
                      Vector columnData, JTable table) {

    int moveTo = ((Integer)columnName);
    boolean unselected = moveTo==-1;
    super.addColumn(this.getColumnCount(), columnData);
    if(!unselected) {//if a column was selected 
        table.moveColumn(this.getColumnCount()-1, moveTo+1);
    }
}

this works great at the first time, but when i add another column it kind of moves also the other(before added columns). 这在第一次时效果很好,但是当我添加另一列时,它也会移动另一列(在添加列之前)。

I don't understand what that means. 我不明白那是什么意思。

If you need more help post your SSCCE that demonstrates the problem. 如果您需要更多帮助,请发布SSCCE来演示问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM