String[] options = {"Option 1", "Option 2", "Option 3"}; JListlist = new JList (); list.setListData(options);
class Employee { private String name; private int age; //constructor and getters-setters } Employee[] employees = {new Employee("John", 25), new Employee("Jane", 30)}; JListIn both examples, the setListData method is used to set the data for the JList. The first example sets an array of strings as the data for the JList, while the second example sets an array of custom objects (Employee) as the data for the JList. The package library used in these examples is javax.swing.employeeList = new JList (); employeeList.setListData(employees);