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[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); // Get number of items in the list int size = list.getModel().getSize(); // 4 // Get all item objects for (int i = 0; i < size; i++) { Object item = list.getModel().getElementAt(i); }//ww w.j a v a2 s . c om }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); // Set the item width int cellWidth = 200; list.setFixedCellWidth(cellWidth);//from w ww. jav a 2s .co m // Set the item height int cellHeight = 18; list.setFixedCellHeight(cellHeight); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); // Get the index of all the selected items int[] selectedIx = list.getSelectedIndices(); // Get all the selected items using the indices for (int i = 0; i < selectedIx.length; i++) { Object sel = list.getModel().getElementAt(selectedIx[i]); }// w w w .j a va 2 s.c o m // Get the index of the first selected item int firstSelIx = list.getSelectedIndex(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Object[] items2 = { new Integer(123), new java.util.Date() }; JList list = new JList(items2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); JScrollPane scrollingList = new JScrollPane(list); // Change orientation to top-to-bottom, left-to-right layout list.setLayoutOrientation(JList.VERTICAL); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); JScrollPane scrollingList = new JScrollPane(list); // Change orientation to top-to-bottom, left-to-right layout list.setLayoutOrientation(JList.HORIZONTAL_WRAP); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); JScrollPane scrollingList = new JScrollPane(list); // Change orientation to top-to-bottom, left-to-right layout list.setLayoutOrientation(JList.VERTICAL_WRAP); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); JScrollPane scrollingList = new JScrollPane(list); // Make the number of rows dynamic list.setVisibleRowCount(0);/*w w w .j a v a 2 s. c om*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); JScrollPane scrollingList = new JScrollPane(list); // The default layout orientation is JList.VERTICAL int orient = list.getLayoutOrientation(); // Change the layout orientation to left-to-right, top-to-bottom list.setLayoutOrientation(JList.HORIZONTAL_WRAP); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "B", "C", "D" }; JList list = new JList(items); list.setSelectionMode(DefaultListSelectionModel.SINGLE_INTERVAL_SELECTION); }