I'm doing an application with java and swing and I need to recover the element marked by the user from a JList. I perform the same steps as in two checkboxes, but when doing
for (int i = 0; i < listadoEspecialidades.getModel().getSize(); i++) {
String[] listado = new String[i+1];
listado[i] = String.valueOf(listadoEspecialidades.getModel().getElementAt(i));
rbEspecialidad.setActionCommand(listado[i]);
}
btgEspecialidades.add(rbEspecialidad);
Later, I try to recover btgEspecialidades
String especialidad = btgEspecialidades.getSelection().getActionCommand();
But it comes null