0

我有一个JTable使用AbstractTableModel. 我正在尝试使表格的第一行成为JCheckboxes.

编辑:目标是使用选中复选框的列并创建一个新表。这是我第一次尝试这样的事情,所以我愿意接受建议。

这是我在 NetBeans 7.1.1 中尝试的代码:

private void selectSourceCBActionPerformed(java.awt.event.ActionEvent evt) {                                           
        int sourceNum = selectSourceCB.getSelectedIndex();

        DataSource currentDS = datSourceArrList.get(sourceNum);
        final ArrayList<Object[]> workArrLst1 = currentDS.getSampSet();

        sourceDetailTable.setAutoResizeMode(sourceDetailTable.AUTO_RESIZE_OFF);
        sourceDetailTable.setColumnSelectionAllowed(true);
        JTableHeader header = sourceDetailTable.getTableHeader();

        AbstractTableModel mytable1 = new AbstractTableModel() {
        Object colNames[] = workArrLst1.get(0);

            @Override
            public int getRowCount() {
                return workArrLst1.size();
            }

            @Override
            public int getColumnCount() {
                return workArrLst1.get(1).length;
            }

            @Override
            public Object getValueAt(int rowIndex, int columnIndex) {
                return workArrLst1.get(rowIndex+1)[columnIndex];
             }

            @Override
            public void setValueAt(Object value, int row, int col) {
                if(row == 1){
                        workArrLst1.get(row)[col] = Boolean(false);
                        fireTableCellUpdated(row, col);
                }
            workArrLst1.get(row)[col] = (String) value;
            fireTableCellUpdated(row, col);
            }

            @Override
            public String getColumnName(int column) {
                return (String) colNames[column];
            }

        };    

    } 

我在这里有什么明显的遗漏吗?

4

0 回答 0