JList is a component of javax.swing library in Java that provides a user interface to display a list of items. The isSelectionEmpty method of JList is used to determine if there are any selected items in the list.
Example 1:
//creating a new JList JList myList = new JList();
//checking if the list is empty if(myList.isSelectionEmpty()){ System.out.println("No items selected"); }else{ System.out.println("Items selected"); }
Example 2:
//creating a new JList with items String[] items = {"Item 1","Item 2","Item 3"}; JList myList = new JList(items);
//selecting an item from the list myList.setSelectedIndex(0);
//checking if the item is selected if(myList.isSelectionEmpty()){ System.out.println("No items selected"); }else{ System.out.println("Item selected: " + myList.getSelectedValue()); }
The javax.swing library is a part of the Java Foundation Classes (JFC) that provides a set of GUI components for creating desktop applications.
Java JList.isSelectionEmpty - 21 examples found. These are the top rated real world Java examples of javax.swing.JList.isSelectionEmpty extracted from open source projects. You can rate examples to help us improve the quality of examples.