繁体   English   中英

多选JTable +组合框(celleditor)+单击

[英]Multi Selection JTable + Combobox (celleditor) + Click

我有一个可以接受多重选择的表格。 在此jtable上,添加一列,然后添加一个组合框,如下所示:

public void setPriorityEditor(final String columnName) {
        final TableColumn col = ((BasicTableModel) table.getModel())
            .findTableColumn(columnName);
        col.setCellEditor(new PriorityComboBoxEditor());
    }

我想实现一个新功能:可以使用组合框来更新多个字段,这是我选择的一部分。 http://imageshack.us/photo/my-images/40/qyks.png/当我想在选择区域中选择一行时,我的问题就开始了。选择多行,选择是刷新的,现在我只有一行已选择。 可能吗?

摘要:尝试使用多选更新几列。 行包含带有组合框的列。 选择几行,然后使用组合框(属于所选行的一部分)用组合框的值更新所有特定行的列。

问候大家。

所以我像这样在changeSelection()方法中更改代码:

if (extend) {
            super.changeSelection(rowIndex, columnIndex, toggle, extend);
            listTest = new ArrayList<Object>();
            for (int e : modelTable.getToolTipsJTable().getSelectedRows()) {
                listTest.add(e);
            }
            isExtend = true;
        } else {
            // super.changeSelection(rowIndex, columnIndex, toggle, extend);
            if (modelTable.getToolTipsJTable().getSelectedRows().length > 1) {
                listTest = new ArrayList<Object>();
                for (int e : modelTable.getToolTipsJTable()
                    .getSelectedRows()) {
                    listTest.add(e);
                }
                isExtend = true;
            }
            if (isExtend) {
                boolean isSame = false;
                for (Object i : listTest) {
                    if (((Integer) i).intValue() == rowIndex) {
                        isSame = true;
                    }
                }
                if (!isSame) {
                    isExtend = false;
                    super.changeSelection(rowIndex, columnIndex, toggle,
                        extend);
                }
            } else {
                super
                    .changeSelection(rowIndex, columnIndex, toggle, extend);
            }
        }

它仅用于分析,忘记清洁度和性能:D如果您需要更多信息,请添加注释。

暂无
暂无

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

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