JListmyList = new JList (new String[] {"Item 1", "Item 2", "Item 3"}); myList.setForeground(Color.RED); // Set the foreground color of JList items to red
Color color = myList.getForeground(); // Get the foreground color of JList itemsThis example gets the foreground color of the JList items using the getForeground() method and stores it in a Color object called "color". Package library: javax.swing