Delete selection from a List

0

In my java class I created a form and created a button that cleans all fields.

But I can not get it to delete the selection of a list that I have on the form, it deletes the textfield and radios butto n but not the list.

Note: I'm not using JList and yes List. I've tried this way 'HostName.clearSelection ();' but the code turns red incorrect and does not deselect the item.

NomeCurso = new List(5, false);
Nome Curso.setSize(200, 170);
NomeCurso.setLocation(480, 145);
NomeCurso.addItem("Adm");
NomeCurso.addItem("Biomedicina");
NomeCurso.addItem("Ciencia da computacao");
NomeCurso.addItem("Farmacia");
NomeCurso.addItem("Direito");
NomeCurso.addItem("Educação física");

...

getContentPane().add(NomeCurso);
    
asked by anonymous 02.11.2016 / 18:43

1 answer

1

For the java.awt.List package, according to the Javadoc available at List , to clear the selection you must use the removeAll(int index) method. The index can be given by the getSelectedIndex() method; It would look something like this:

NomeCurso.deselect(NomeCurso.getSelectedIndex());

By the way, if you're using Swing it's best to use JList.

    
02.11.2016 / 18:54