我在我的专栏中创建了 JComboBox,它工作正常。当我尝试在同一列中再添加一个编辑器时,就会出现问题。场景,用户需要从 ComboBox 中选择值作为他们的备注。如果他们选择其他,另一个文本框应出现在组合框下方供用户键入。
组合框代码
TableColumn col5 = jTable1.getColumnModel().getColumn(4);
String[] options = new String[]{"Font Issue","Text Issue","Image Issue","AI Issue","Others"};
JComboBox combo1 = new JComboBox(options);
JComboBox combo2 = new JComboBox(options);
col5.setCellEditor(new DefaultCellEditor(combo1));
col5.setCellRenderer(new ComboBoxRenderer(combo2));
combo2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox nameCombo = (JComboBox)e.getSource();
String newSelection = (String)nameCombo.getSelectedItem();
if(newSelection.equalsIgnoreCase("others"))
{
}
}
});
当我再添加一个编辑器时。
MyTableCellEditor textEditor = new MyTableCellEditor ();
col5.setCellEditor(textEditor );
它会覆盖下拉列表。我想要这样的东西。