JListmyList = new JList (new String[]{"Apple", "Banana", "Cherry"}); myList.clearSelection();
DefaultListModelIn this example, we create a DefaultListModel of strings with three items: "Dog", "Cat", and "Fish". We create a JList using this model and select the second item ("Cat"). We then call the clearSelection() method on the list, which clears the selection and ensures that no item is selected. Package library: javax.swing.model = new DefaultListModel (); model.addElement("Dog"); model.addElement("Cat"); model.addElement("Fish"); JList myList = new JList (model); myList.setSelectedIndex(1); myList.clearSelection();