I need help to include a value in the ID column when in the column on the NAME side select a particular item (Drug).
I can make the items appear with the combo but when I select the drug I do not know how to put the ID of it in that ID column.
private void initTableReceita() throws ClassNotFoundException, SQLException{
DefaultTableModel dftm = (DefaultTableModel) tabelaMedicamentos.getModel();
arrayDosagem = new String[]{ Medicamento.ViaAdministracao.INTRAMUSCULAR.name(),
Medicamento.ViaAdministracao.ORAL.name(),
Medicamento.ViaAdministracao.SUBLINGUAL.name(),
Medicamento.ViaAdministracao.VENOSA.name()};
arrayViaAdministracao = new String[]{ Medicamento.ViaAdministracao.INTRAMUSCULAR.name(),
Medicamento.ViaAdministracao.ORAL.name(),
Medicamento.ViaAdministracao.SUBLINGUAL.name(),
Medicamento.ViaAdministracao.VENOSA.name()};
//-----------------------------------------------------------------
MedicamentoDAO medicamentoDAO = new MedicamentoDAO();
ArrayList<Medicamento> listaMedicamento = medicamentoDAO.buscarTodos();
String[] arrayMedicamento = new String[listaMedicamento.size()];
for(int i = 0; i< listaMedicamento.size(); i++){
arrayMedicamento[i] = listaMedicamento.get(i).getNome();
}
comboBoxMedicamento = new JComboBox<>(arrayMedicamento);
TableColumn colunaNomeMedicamento = tabelaMedicamentos.getColumnModel().getColumn(1);
colunaNomeMedicamento.setCellEditor(new DefaultCellEditor(comboBoxMedicamento));
comboBoxMedicamento.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Medicamento medicamento = (Medicamento)comboBoxMedicamento.getSelectedItem();
dftm.addRow(new Integer[]{medicamento.getId()});
}
});
//Medicamento selecionado na coluna do lado 'Nome' do medicamento
//-----------------------------------------------------------------
comboBoxViaAdmin = new JComboBox<>(arrayViaAdministracao);
//String tipoUsuario = jComboBox1.getSelectedItem().toString();
TableColumn colunaViaAdministracao = tabelaMedicamentos.getColumnModel().getColumn(3);
colunaViaAdministracao.setCellEditor(new DefaultCellEditor(comboBoxViaAdmin));
}