2013-08-01 39 views
0

我在我的列中创建了JComboBox,它工作正常。当我试图在同一列中添加一个更多编辑器时,就会出现问题。情景中,用户需要从ComboBox中选择值作为他们的评论。如果他们选择其他,则另一个文本框应出现在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);

它覆盖下拉列表。我想有这样的事情。

enter image description here

+0

也许这是我,但我很不清楚你想做什么。如果您很快就没有得到像样的答案,请考虑更详细地描述事情。 –

+0

我想创建Jcombobox和texteditor像上面我的照片一样的单元格。 –

回答

2

摇摆编辑被设计成占据一个单电池的空间。如果要显示带有两个组件的面板,则需要创建一个弹出式编辑器。阅读Swing教程Using Other Editors中的部分,了解如何执行此操作的示例。

相关问题