Is it possible to select several data inserted in a jList in java?

0

How can I select 3 data from a list in java?

With this code I can only select a value from the list, I need to select 3 of them and save them in each of the String variables that appear there.

String apunt,apunt2,apunt3; 

if(ListaUno.isSelectionEmpty()){ JOptionPane.showMessageDialog(null, " 
Seleccione un valor de la Lista "); } 
else{ 
apunt=ListaUno.getSelectedValue(); Ley obj=new Ley(); obj.setDato(apunt); 
obj.setModelo(modelo); JOptionPane.showMessageDialog(null,"es"); [![introducir la descripción de la imagen aquí][1]][1]
} 
    
asked by Daniel Peñaloza 05.06.2017 в 16:49
source

1 answer

1

You just have to set this attribute from your list:

JList lista = new JList();
lista.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

//este retorna un array de los valores seleccionados
lista.getSelectedIndices();

//Este retorna una lista de los valores seleccionados
lista.getSelectedValuesList();

At your own expense you will know what to use

    
answered by 05.06.2017 в 17:14