JList myList = new JList(); myList.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
JList myList = new JList(); myList.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.red),"My List"));This example is also using the BorderFactory class from the javax.swing.BorderFactory package to create a titled border around the JList component. In both examples, the setBorder method is being used to set the border of the JList component. The first argument of the method is an object that specifies the type of border to be used, and the second argument is an object that allows the border to be customized. The package library used in these examples is javax.swing.BorderFactory.