문제

I created JComboBox in my column and it works fine. The problem occurs when I tried to add one more editor in the same column. Scenario, user need to choose value from ComboBox as their remark. If they choose Others, another textbox should appear below the ComboBox for user to type.

Code for 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"))
                {                        
                }
            }
        });

When i add one more editor.

MyTableCellEditor textEditor = new MyTableCellEditor (); col5.setCellEditor(textEditor );

It overwrite the dropdownlist. I want to have something like this.

enter image description here

도움이 되었습니까?

해결책

Swing editors are designed to occupy the space of a single cell. If you want to display a panel with two components then you will need to create a popup editor. Read the section from the Swing tutorial on Using Other Editors for an example of how you might do this.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top