Combobox dependent on another combobox in jtable

0

I have the following situation, in a table I have the department column and another city, the intention is that when you select a department that would be in column 0, the city combobox will automatically load in the next column in the active row. cities related to that department.

I understand that the process must be done in the action comformed of the department combo so that when I select one I automatically load the combo of the cities, the issue is that I do not know what event I should use that allows me to manipulate the table in order to change the cellleditor from the column in the row selected for the city and I loaded the list.

I appreciate the help you can give me with the subject.

Thanks

    
asked by Oscar Mauricio Gomez Acevedo 22.07.2018 в 01:58
source

1 answer

0

I tell you that I could solve it in the following way, I share code:

    dpto.addActionListener(new ActionListener() {</i>
        @Override
        public void actionPerformed(ActionEvent ae) {
            JComboBox dpto = (JComboBox) ae.getSource();
            JComboBox ciudad= new JComboBox();
            String departamento="";
            if (dpto.getSelectedIndex() > -1) {
                TableColumn ciudadColumn = 
                tabla.getColumnModel().getColumn(3);
                departamento=      ((Departamento)dpto.getSelectedItem()).getCodDepartamento();
                ciudad.removeAllItems();
                tabla.setValueAt(new Ciudad(), tabla.getSelectedRow(), 3);
                for (Ciudad c : new Ciudad().consultarCiudadesxdepartamento(departamento)) {
                    ciudad.addItem(c);
                    ciudad.setSelectedIndex(-1);
                }
                ciudadColumn.setCellEditor(new DefaultCellEditor(ciudad));
            }
        }
    });  

It is already working and we are all very happy, thanks to those who were interested, if you have any questions, I remain attentive.

    
answered by 23.07.2018 в 21:40