List of usage examples for javax.swing.event ListSelectionEvent getLastIndex
public int getLastIndex()
From source file:Main.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); ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { System.out.println("First index: " + listSelectionEvent.getFirstIndex()); System.out.println(", Last index: " + listSelectionEvent.getLastIndex()); boolean adjust = listSelectionEvent.getValueIsAdjusting(); System.out.println(", Adjusting? " + adjust); if (!adjust) { JList list = (JList) listSelectionEvent.getSource(); int selections[] = list.getSelectedIndices(); Object selectionValues[] = list.getSelectedValues(); for (int i = 0, n = selections.length; i < n; i++) { if (i == 0) { System.out.println(" Selections: "); }// w w w.j ava 2s . c o m System.out.println(selections[i] + "/" + selectionValues[i] + " "); } } } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); 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("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1);/*from www .ja v a2 s .c o m*/ ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { System.out.println("First index: " + listSelectionEvent.getFirstIndex()); System.out.println(", Last index: " + listSelectionEvent.getLastIndex()); boolean adjust = listSelectionEvent.getValueIsAdjusting(); System.out.println(", Adjusting? " + adjust); if (!adjust) { JList list = (JList) listSelectionEvent.getSource(); int selections[] = list.getSelectedIndices(); Object selectedValues[] = list.getSelectedValues(); for (int i = 0, n = selections.length; i < n; i++) { if (i == 0) { System.out.println(" Selections: "); } System.out.println(selections[i] + "/" + selectedValues[i] + " "); } } } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:SelectingJListSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame frame = new JFrame("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JList jlist = new JList(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); contentPane.add(scrollPane1, BorderLayout.WEST); ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { System.out.print("First index: " + listSelectionEvent.getFirstIndex()); System.out.print(", Last index: " + listSelectionEvent.getLastIndex()); boolean adjust = listSelectionEvent.getValueIsAdjusting(); System.out.println(", Adjusting? " + adjust); if (!adjust) { JList list = (JList) listSelectionEvent.getSource(); int selections[] = list.getSelectedIndices(); Object selectionValues[] = list.getSelectedValues(); for (int i = 0, n = selections.length; i < n; i++) { if (i == 0) { System.out.print(" Selections: "); }//from w w w .j a v a 2s . c o m System.out.print(selections[i] + "/" + selectionValues[i] + " "); } System.out.println(); } } }; jlist.addListSelectionListener(listSelectionListener); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); System.out.println("Double-clicked on: " + o.toString()); } } } }; jlist.addMouseListener(mouseListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:SelectionMonitor.java
public void valueChanged(ListSelectionEvent e) { if ((!e.getValueIsAdjusting()) || (e.getFirstIndex() == -1)) return;/*w w w. jav a2 s . co m*/ for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) { System.out.println(((JList) e.getSource()).isSelectedIndex(i)); } }
From source file:Main.java
public void valueChanged(ListSelectionEvent e) { if (e.getSource() == table.getSelectionModel() && table.getRowSelectionAllowed()) { int first = e.getFirstIndex(); int last = e.getLastIndex(); } else if (e.getSource() == table.getColumnModel().getSelectionModel() && table.getColumnSelectionAllowed()) { int first = e.getFirstIndex(); int last = e.getLastIndex(); }/*w w w.j ava 2 s . c om*/ if (e.getValueIsAdjusting()) { System.out.println("The mouse button has not yet been released"); } }
From source file:SharedListSelectionHandler.java
public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); int firstIndex = e.getFirstIndex(); int lastIndex = e.getLastIndex(); boolean isAdjusting = e.getValueIsAdjusting(); System.out.println("Event for indexes " + firstIndex + " - " + lastIndex + "; isAdjusting is " + isAdjusting + "; selected indexes:"); if (lsm.isSelectionEmpty()) { System.out.println(" <none>"); } else {/*from ww w . j a v a2s . com*/ // Find out which indexes are selected. int minIndex = lsm.getMinSelectionIndex(); int maxIndex = lsm.getMaxSelectionIndex(); for (int i = minIndex; i <= maxIndex; i++) { if (lsm.isSelectedIndex(i)) { System.out.println(" " + i); } } } }
From source file:Main.java
Main() { Container cp = getContentPane(); cp.setLayout(new FlowLayout()); ArrayList data = new ArrayList(); data.add("Hi"); data.add("Hello"); data.add("Goodbye"); list = new JList(data.toArray()); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); }/*from ww w.j av a 2 s .co m*/ }); cp.add(new JScrollPane(list), BorderLayout.CENTER); }
From source file:MainClass.java
MainClass() { Container cp = getContentPane(); cp.setLayout(new FlowLayout()); ArrayList data = new ArrayList(); data.add("Hi"); data.add("Hello"); data.add("Goodbye"); list = new JList(data.toArray()); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); }//from ww w . j a va 2 s.c o m }); cp.add(new JScrollPane(list), BorderLayout.CENTER); }
From source file:JListDemo.java
JListDemo(String s) { super(s);/*from w ww . ja va 2s. com*/ Container cp = getContentPane(); cp.setLayout(new FlowLayout()); ArrayList data = new ArrayList(); data.add("Hi"); data.add("Hello"); data.add("Goodbye"); data.add("Adieu"); data.add("Adios"); list = new JList(data.toArray()); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); } }); cp.add(list, BorderLayout.CENTER); }
From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java
private void FilterListSelected(ListSelectionEvent evt) { updating = true;/*from w ww . j a v a 2s . co m*/ int row = filterTable.getSelectedRow(); int last = evt.getLastIndex(); saveData(prevSelRow); if (isValid(row)) { loadData(row); } else if (isValid(last)) { loadData(last); row = last; } String type = (String) filterTable.getValueAt(row, RULE_TYPE_COL); rulePanel.showCard(type); filterTable.setRowSelectionInterval(row, row); prevSelRow = row; updateTaskPane(type); updateCodePanel(null); updating = false; }