简体   繁体   中英

Multi Selection JTable + Combobox (celleditor) + Click

I have a table that accepts multi selection. On this jtable I add a column that I add a combobox like this:

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

I would like to implement a new feature: to can update several field using a combobox which is part of my selection. http://imageshack.us/photo/my-images/40/qyks.png/ My probleme begin when i want to select a row wich part in my selection avec select several row, selection is refresh and i have now just one row selected. Is it possible?

Summary : Try to update severals columns with multi selection. Rows contain a column with a combobox. Select severals rows and use a combobox(which is part of selected rows) for update all the rows specific column with the value of combobox.

Regards guys.

So i change code in changeSelection() methode like this:

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);
            }
        }

It's just for analyse, forgot cleanliness and performance :D If you need more informations add comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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