简体   繁体   English

如何使用Jtable中行中第一个单元格的单元格编辑器编辑连续的所有单元格?

[英]how to edit all cells in a row with the cell editor of first cell in the row in the Jtable?

I have a JTable with 6 columns. 我有一个6列的JTable。 for column 0 and 1 i have created a comboBox as editor. 对于第0列和第1列,我创建了一个comboBox作为编辑器。 I want all the cells in the same row be edited when user select an item from combobox of column 0. 当用户从第0列的组合框中选择项目时,我希望编辑同一行中的所有单元格。

Does any one know if it is the best way or is there other way much better? 有没有人知道这是最好的方式还是其他方式更好?

JTable table = new JTable();// a table with 6 columns
TableColumn column0 = tabel.getColumnModel().getColumn(0);
comboBox = new JComboBox(summary.getGenerics());
column0.setCellEditor(new DefaultCellEditor(comboBox));
column0.setCellRenderer(new DefaultTableCellRenderer());
comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              String selectedItem = comboBox.getSelectedItem().toString();
               table.setValueAt("class" , table.getSelectedRow() , 1);

            }
        });

This example overrides getValueAt() to condition the value returned by a dependent column based on the selection in a column having a JComboBox editor. 示例重写getValueAt()以根据具有JComboBox编辑器的列中的选择来调整依赖列返回的值。 Any dependent column should be non -editable, and any TableModelListener should be notified, as shown here . 任何相关字段是否应该是非 -editable,任何TableModelListener应通知,如图所示这里

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

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