Good morning, I have a list of some reasons
private List<Motivo> motivos;
I need to populate a jComboBox with this list and get the selected option.
Currently I have done with MessageDialog where I can fill normally but I can not get the selected item, for example:
JComboBox jcb = new JComboBox();
for (Motivo motivos_bloqueia : motivos) {
jcb.addItem(motivos_bloqueia.getMotivo());
}
JOptionPane.showMessageDialog(null, jcb, "Selecione o motivo", JOptionPane.QUESTION_MESSAGE);
But this way I can not get the selected item.
I read in some forums where I was directed to use an InputDialog instead of MessageDialog, as follows:
Object[] opcoes = {"Um","Dois","Tres","Quatro"};
Object res = JOptionPane.showInputDialog(null, "Escolha um item" , "Selecao
de itens" ,
JOptionPane.PLAIN_MESSAGE , null ,opcoes,"");
That way I would have the item selected in the 'res' variable. The problem is that the parameter that it passes to the combobox add the items in the options is an Object [] and in case what I have is a List.
How do I get the item that the user selected in the combobox by clicking OK?