List of usage examples for javax.swing JList JList
public JList(final Vector<? extends E> listData)
JList
that displays the elements in the specified Vector
. From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist1 = new JList(labels); jlist1.setVisibleRowCount(4);/*w w w . j a v a 2 s . c o m*/ JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setSelectionBackground(Color.RED); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String[] selections = { "green", "red", "orange", "dark blue" }; JList list = new JList(selections); list.setSelectedIndex(1);//from w w w . j av a 2 s. c om System.out.println(list.getSelectedValue()); frame.add(new JScrollPane(list)); frame.pack(); frame.setVisible(true); }
From source file:JListSelectionModeAnchor.java
public static void main(String args[]) { JFrame frame = new JFrame("Modifying Model"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(new String[] { "A", "B", "C" }); jlist.getSelectionModel().setAnchorSelectionIndex(0); jlist.getSelectionModel().setLeadSelectionIndex(2); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); frame.setSize(640, 300);/* www.j ava2s. c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String subject[] = { "Math", " English", "SQL", " java", " c ", " c++ ", " cobol ", "this is a test" }; JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList<String> list = new JList<String>(subject); JScrollPane s = new JScrollPane(list); s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); f.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); f.add(s);//from w w w . java 2 s. co m f.setSize(300, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); for (int i = 0; i < 30; i++) { list.add("Hello, World " + i); }//from w w w.j ava 2 s . c o m JScrollPane pane = new JScrollPane(new JList(list.toArray())) { @Override public Dimension getPreferredSize() { return new Dimension(200, 250); } }; JOptionPane.showMessageDialog(null, pane); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist1 = new JList(labels); jlist1.setVisibleRowCount(4);/*from ww w . jav a 2 s. c o m*/ JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JScrollPane listScrollPane = new JScrollPane(); String[] stringArray = { "Testing", "This", "Stuff" }; JList<String> rowList = new JList<>(stringArray); rowList.setVisibleRowCount(2);/*from w ww. jav a2 s . c o m*/ listScrollPane.setViewportView(rowList); panel.setLayout(new BorderLayout()); panel.add(listScrollPane); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> data = new Vector<String>(); for (int i = 1; i < 100; i++) { data.add("Entry " + i); }/* w w w . j a va2 s . co m*/ JList<String> list = new JList<>(data); list.setVisibleRowCount(8); JScrollPane scrollPane = new JScrollPane(list); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:ListSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; String title = "JList Sample"; JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list = new JList(labels); JScrollPane scrollPane = new JScrollPane(list); Container contentPane = f.getContentPane(); contentPane.add(scrollPane, BorderLayout.CENTER); f.setSize(200, 200);/*from ww w.j av a2 s . c om*/ f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] names = { "John Smith", "this is a test", "this is a test. this is a test. " }; MyCellRenderer cellRenderer = new MyCellRenderer(80); JList<String> list = new JList<>(names); list.setCellRenderer(cellRenderer);//from w w w .j a va 2 s .c o m JScrollPane sPane = new JScrollPane(list); JPanel panel = new JPanel(); panel.add(sPane); JOptionPane.showMessageDialog(null, panel); }