new JList(Object[] listData)
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class MainClass {
public static void main(final String args[]) {
String labels[] = { "A", "B", "C", "D", "E" };
JFrame frame = new JFrame("Selection Modes");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JList list1 = new JList(labels);
JScrollPane sp1 = new JScrollPane(list1);
sp1.setColumnHeaderView(new JLabel("List"));
frame.add(sp1, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
Related examples in the same category