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(String args[]) { JPanel p = new JPanel(); p.setLayout(new GridLayout(2, 1)); JList<String> lista = new JList<>(new String[] { "1", "2", "3", "4" }); p.add(new JScrollPane(lista)); JComboBox<String> combo = new JComboBox<>(); for (int i = 0; i < 100; i++) { combo.addItem(Integer.toString(i)); p.add(combo);//w ww . ja v a 2 s. c o m } JFrame f = new JFrame(); f.getContentPane().add(p, BorderLayout.CENTER); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(200, 200); f.setVisible(true); }
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 www .ja v a 2 s . c o m JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setValueIsAdjusting(false); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.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.setSelectedIndex(0);//from ww w . j a va 2s . co m JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); frame.setSize(640, 300); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Multi-Columns"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList columns = new JList(labels); columns.setLayoutOrientation(JList.HORIZONTAL_WRAP); columns.setVisibleRowCount(3);//from w w w .ja v a 2 s .c o m JScrollPane sp = new JScrollPane(columns); frame.add(sp, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] items = new String[] { "One", "Two", "Three", "Four" }; JList<String> list = new JList<>(items); JFrame f = new JFrame(); f.add(list, BorderLayout.CENTER); JButton btn = new JButton("Get selected"); btn.addActionListener(new ActionListener() { @Override/* ww w . j av a2 s .c o m*/ public void actionPerformed(ActionEvent e) { JOptionPane.showConfirmDialog(f, "You Selected : " + list.getSelectedValue(), "Display", JOptionPane.PLAIN_MESSAGE); } }); f.add(btn, BorderLayout.SOUTH); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
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);//from w w w . j ava2s . c o m frame.setVisible(true); }
From source file:JListLocationToIndexSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H" }; JFrame frame = new JFrame("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); System.out.println(jlist.indexToLocation(5)); frame.setSize(350, 200);//from w w w .j a v a2 s .c o m frame.setVisible(true); }
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 av a 2 s. c o m*/ JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setSelectedIndices(new int[] { 1, 2 }); frame.setSize(300, 350); frame.setVisible(true); }
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 w w w .j ava 2s .c o m*/ JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setSelectionForeground(Color.RED); frame.setSize(300, 350); frame.setVisible(true); }
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 w ww. j ava 2s. c o m*/ JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setSelectedIndex(1); frame.setSize(300, 350); frame.setVisible(true); }