JListmyList = new JList (new String[] {"Item 1", "Item 2", "Item 3"}); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setSelectionBackground(Color.GREEN);
JListThis example creates a JList component with three items and sets its selection mode to allow multiple items to be selected. It then sets the selection background color to a light blue color defined by the RGB values (135, 206, 250). The javax.swing package library contains the JList class and its associated methods.myList = new JList (new String[] {"Item 1", "Item 2", "Item 3"}); myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); myList.setSelectionBackground(new Color(135, 206, 250));