Java Code Examples for javax.swing.JList#getSelectedIndices()
The following examples show how to use
javax.swing.JList#getSelectedIndices() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListTransferHandler.java From marathonv5 with Apache License 2.0 | 6 votes |
protected String exportString(JComponent c) { JList list = (JList) c; indices = list.getSelectedIndices(); @SuppressWarnings("deprecation") Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return buff.toString(); }
Example 2
Source File: RJideCheckBoxListItem.java From marathonv5 with Apache License 2.0 | 6 votes |
public String getValue() { CheckBoxListCellRenderer cbListRenderer = (CheckBoxListCellRenderer) getComponent(); if (cbListRenderer instanceof JComponent) { JList list = (JList) cbListRenderer.getClientProperty("jlist"); if (list.getSelectedIndices().length > 1) { return null; } } Component[] childern = cbListRenderer.getComponents(); for (Component c : childern) { if (c instanceof JCheckBox) { return String.valueOf(((JCheckBox) c).isSelected()); } } return null; }
Example 3
Source File: QueryParameter.java From netbeans with Apache License 2.0 | 6 votes |
public ListParameter(JList list, String parameter, String encoding) { super(parameter, encoding); this.list = list; list.setModel(new DefaultListModel()); list.addListSelectionListener(new ListSelectionListener(){ @Override public void valueChanged(ListSelectionEvent e) { int[] s = ListParameter.this.list.getSelectedIndices(); if(e.getValueIsAdjusting()) { return; } fireStateChanged(); }; }); original = list.getSelectedIndices(); fireStateChanged(); }
Example 4
Source File: TableUISupport.java From jeddict with Apache License 2.0 | 6 votes |
public static Set<Table> getSelectedTables(JList list, boolean enabledOnly) { Set<Table> result = new HashSet<>(); int[] selected = list.getSelectedIndices(); for (int i = 0; i < selected.length; i++) { Table table = (Table) list.getModel().getElementAt(selected[i]); if (enabledOnly) { if (!list.getCellRenderer().getListCellRendererComponent(list, table, selected[i], false, false).isEnabled()) { continue; } } result.add(table); } return result; }
Example 5
Source File: DifferencesManagementPanel.java From swift-explorer with Apache License 2.0 | 6 votes |
private List<ComparisonItem> getSelectedItems(JList<ComparisonItem> list, DefaultListModel<ComparisonItem> listModel, boolean removeFromModel) { List<ComparisonItem> results = new ArrayList<ComparisonItem>(); int[] indices = list.getSelectedIndices() ; for (int index : indices) { results.add(listModel.get(index)) ; } if (removeFromModel) { // we must remove the element in a correct order for (int i = indices.length - 1 ; i >= 0 ; --i) { listModel.remove(indices[i]); } } return results; }
Example 6
Source File: JListJavaElement.java From marathonv5 with Apache License 2.0 | 5 votes |
public String getSelectionText(JList list) { List<Properties> pa = new ArrayList<Properties>(); int[] selectedIndices = list.getSelectedIndices(); for (int index : selectedIndices) { Properties p = new Properties(); p.setProperty("listText", new JListItemJavaElement(this, index)._getText()); pa.add(p); } return PropertyHelper.toString(pa.toArray(new Properties[pa.size()]), new String[] { "listText" }); }
Example 7
Source File: RList.java From marathonv5 with Apache License 2.0 | 5 votes |
public String getSelectionText(JList list) { List<Properties> pa = new ArrayList<Properties>(); int[] selectedIndices = list.getSelectedIndices(); for (int index : selectedIndices) { Properties p = new Properties(); p.setProperty("listText", getText(list, index)); pa.add(p); } return PropertyHelper.toString(pa.toArray(new Properties[pa.size()]), new String[] { "listText" }); }
Example 8
Source File: TableUISupport.java From netbeans with Apache License 2.0 | 5 votes |
public static Set<Table> getSelectedTables(JList list, boolean enabledOnly) { Set<Table> result = new HashSet<Table>(); int[] selected = list.getSelectedIndices(); for (int i = 0; i < selected.length; i++) { Table table = (Table)list.getModel().getElementAt(selected[i]); if(enabledOnly){ if(!list.getCellRenderer().getListCellRendererComponent(list, table, selected[i], false, false).isEnabled())continue; } result.add(table); } return result; }
Example 9
Source File: FolderList.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Transferable createTransferable(JComponent comp) { final JList list = (JList)comp; indices = list.getSelectedIndices(); if (indices.length == 0) { return null; } return new FileListTransferable(safeCopy(list.getSelectedValues(),File.class)); }
Example 10
Source File: CodeCompletionPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void javaCompletionExcluderRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javaCompletionExcluderRemoveButtonActionPerformed JList list = getSelectedExcluderList(); int[] rows = list.getSelectedIndices(); DefaultListModel model = (DefaultListModel) list.getModel(); // remove rows in descending order: row numbers change when a row is removed for (int row = rows.length - 1; row >= 0; row--) { model.remove(rows[row]); } updateExcluder(list); }
Example 11
Source File: TradeRouteInputPanel.java From freecol with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected Transferable createTransferable(JComponent c) { JList list = (JList)c; final DefaultListModel model = (DefaultListModel)list.getModel(); int[] indicies = list.getSelectedIndices(); List<TradeRouteStop> stops = new ArrayList<>(indicies.length); for (int i : indicies) stops.add(i, (TradeRouteStop)model.get(i)); return new StopListTransferable(stops); }
Example 12
Source File: Validator.java From dualsub with GNU General Public License v3.0 | 5 votes |
public static int[] isSelected(JList<File> list) { int[] selected = list.getSelectedIndices(); if (selected.length < 1) { Alert.error(I18N.getHtmlText("Validator.selectOne.alert")); } return selected; }
Example 13
Source File: InjectScript.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
@Override protected Transferable createTransferable(JComponent c) { JList list = (JList) c; return new JListTransferable(list.getSelectedIndices()); }
Example 14
Source File: DifferencesManagementPanel.java From swift-explorer with Apache License 2.0 | 4 votes |
public boolean isSingleStoredObjectSelected(JList<ComparisonItem> list) { return list.getSelectedIndices().length == 1; }
Example 15
Source File: MainActivity.java From Raccoon with Apache License 2.0 | 4 votes |
private void doImport() { try { String data = (String) Toolkit.getDefaultToolkit().getSystemClipboard() .getData(DataFlavor.stringFlavor); String prefix = "market://details?id="; //$NON-NLS-1$ StringTokenizer st = new StringTokenizer(data); Vector<String> lst = new Vector<String>(); int count = 0; while (st.hasMoreElements()) { // Lets first check the entire clipboard if its content is well formed. String url = st.nextToken(); if (url.startsWith(prefix) && url.length() > prefix.length()) { // Let's keep it simple. String id = url.substring(prefix.length(), url.length()); if (!lst.contains(id) && !archive.fileUnder(id, 0).getParentFile().exists()) { lst.add(id); count++; } } } // We got at least one new app id. Ask the user to confirm the list, then // create files. if (count > 0) { JList<String> all = new JList<String>(lst); all.addSelectionInterval(0, lst.size() - 1); if (JOptionPane .showConfirmDialog( this, new JScrollPane(all), Messages.getString("MainActivity.42"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null) == JOptionPane.OK_OPTION) {//$NON-NLS-1$ int[] sel = all.getSelectedIndices(); for (int idx : sel) { archive.fileUnder(all.getModel().getElementAt(idx), 0).getParentFile().mkdirs(); } searchView.doMessage(Messages.getString("MainActivity.39")); //$NON-NLS-1$ } } else { // Tell the user that no new items were found. searchView.doMessage(Messages.getString("MainActivity.43")); //$NON-NLS-1$ } } catch (Exception e) { searchView.doMessage(Messages.getString("MainActivity.40")); //$NON-NLS-1$ // e.printStackTrace(); } }