Java Code Examples for javax.swing.DefaultListModel#add()
The following examples show how to use
javax.swing.DefaultListModel#add() .
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: SelectRootsPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void browse(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browse try { final Collection<Integer> added = new ArrayList<>(); final List<? extends String> paths = browseCall.call(); if (paths != null) { final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel(); final Set<URI> contained = new HashSet<>(Collections.list(lm.elements())); int index = sources.getSelectedIndex(); index = index < 0 ? lm.getSize() : index + 1; for (String path : paths) { for (URI uri : convertor.call(path)) { if (!contained.contains(uri)) { lm.add(index, uri); added.add(index); index++; } } } } select(added); } catch (Exception ex) { Exceptions.printStackTrace(ex); } }
Example 2
Source File: ConfigurableUserAccessDialog.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Adds the element sorted to the model * * @param model * @param element * @return index of the new element */ private int addElement(DefaultListModel<String> model, String element) { if (model.isEmpty()) { model.addElement(element); return 0; } else { for (int j = 0; j < model.getSize(); j++) { int compareValue = String.CASE_INSENSITIVE_ORDER.compare(model.getElementAt(j).toString(), element); if (compareValue > 0) { model.add(j, element); return j; } if (j == model.getSize() - 1) { model.add(j + 1, element); return j + 1; } } } // sth went wrong return -1; }
Example 3
Source File: ClassPathUiSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static int[] addJarFiles( DefaultListModel listModel, int[] indices, String filePaths[], File base, String[] variables, Callback callback) { int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1]; int[] indexes = new int[filePaths.length]; for( int i = 0, delta = 0; i+delta < filePaths.length; ) { int current = lastIndex + 1 + i; ClassPathSupport.Item item = ClassPathSupport.Item.create( filePaths[i], base, null, variables != null ? variables[i] : null); if (callback != null) { callback.initItem(item); } if ( !listModel.contains( item ) ) { listModel.add( current, item ); indexes[delta + i] = listModel.indexOf( item ); i++; } else { indexes[i + delta] = listModel.indexOf( item ); delta++; } } return indexes; }
Example 4
Source File: ClassPathUiSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static int[] addArtifacts( DefaultListModel listModel, int[] indices, AntArtifactItem artifactItems[], Callback callback) { int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1]; int[] indexes = new int[artifactItems.length]; for( int i = 0; i < artifactItems.length; i++ ) { int current = lastIndex + 1 + i; ClassPathSupport.Item item = ClassPathSupport.Item.create( artifactItems[i].getArtifact(), artifactItems[i].getArtifactURI(), null) ; if (callback != null) { callback.initItem(item); } if ( !listModel.contains( item ) ) { listModel.add( current, item ); } indexes[i] = listModel.indexOf( item ); } return indexes; }
Example 5
Source File: PathUiSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static int[] addFolders(DefaultListModel<BasePathSupport.Item> listModel, int[] indices, String[] files) { int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1]; int[] indexes = new int[files.length]; for (int i = 0, delta = 0; i + delta < files.length;) { int current = lastIndex + 1 + i; BasePathSupport.Item item = BasePathSupport.Item.create(files[i + delta], null); if (!listModel.contains(item)) { listModel.add(current, item); indexes[delta + i] = current; i++; } else { indexes[i + delta] = listModel.indexOf(item); delta++; } } return indexes; }
Example 6
Source File: InjectScript.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private Boolean reorderProjects(TransferHandler.TransferSupport support) { JList list = (JList) support.getComponent(); try { int[] selectedIndices = (int[]) support.getTransferable().getTransferData(INDICES); DefaultListModel model = (DefaultListModel) list.getModel(); JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() != -1) { for (int selectedIndex : selectedIndices) { Object value = model.get(selectedIndex); model.removeElement(value); model.add(dl.getIndex(), value); } return true; } else { LOG.warning("Invalid Drop Location"); } } catch (UnsupportedFlavorException | IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } return false; }
Example 7
Source File: SliderTester.java From swing_library with MIT License | 6 votes |
private static JList<String> getInner4() { DefaultListModel<String> model = new DefaultListModel<String>(); model.add(0, "Bill Gates"); model.add(1, "Steven Spielberg"); model.add(2, "Donald Trump"); model.add(3, "Steve Jobs"); JList<String> list = new JList<String>(); list.setModel(model); return list; }
Example 8
Source File: BreakpointNestedGroupsDialog.java From netbeans with Apache License 2.0 | 5 votes |
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed int[] indexes = availableGroupsList.getSelectedIndices(); DefaultListModel availableModel = (DefaultListModel) availableGroupsList.getModel(); DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel(); int at = displayedModel.getSize(); for (int i = indexes.length - 1; i >= 0; i--) { Object element = availableModel.remove(indexes[i]); displayedModel.add(at, element); } }
Example 9
Source File: SampleFractionListDisplayPane.java From ET_Redux with Apache License 2.0 | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { // faking out the clipboard with our own clipboard to prevent copying of data objects if (!info.isDrop()) { return false; } DefaultListModel<TripoliFraction> listModel = (DefaultListModel<TripoliFraction>) list.getModel(); // // Get the DragAndDropListItemInterface that is being dropped. // Transferable t = info.getTransferable(); // DragAndDropListItemInterface[] data; // try { // data = (DragAndDropListItemInterface[])t.getTransferData( DataFlavor.stringFlavor );; // } catch (Exception e) { // return false; // } /** * Perform the actual import. Keep items in sort order * */ DragAndDropListItemInterface[] data = reduxDragAndDropClipboardInterface.getDndClipboardListItems(); for (int i = 0; i < data.length; i++) { // find where to insert element in backing list TripoliFraction tf = (TripoliFraction) data[i]; int index = Collections.binarySearch(dndListTripoliFractions, tf); dndListTripoliFractions.add(Math.abs(index + 1), tf); // insert into list as well listModel.add(Math.abs(index + 1), tf); tripoliSample.addTripoliFraction(tf); } closeButton.setEnabled(dndListTripoliFractions.isEmpty()); return true; }
Example 10
Source File: ShowToolSettingsPanel.java From jeveassets with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean importData(TransferSupport info) { TransferHandler.DropLocation tdl = info.getDropLocation(); if (!canImport(info) || !(tdl instanceof JList.DropLocation)) { return false; } JList.DropLocation dl = (JList.DropLocation) tdl; JList<?> target = (JList) info.getComponent(); DefaultListModel<Object> listModel = (DefaultListModel) target.getModel(); int max = listModel.getSize(); int index = dl.getIndex(); index = index < 0 ? max : index; // If it is out of range, it is appended to the end index = Math.min(index, max); addIndex = index; try { Object[] values = (Object[]) info.getTransferable().getTransferData(localObjectFlavor); for (Object value : values) { int idx = index++; listModel.add(idx, value); target.addSelectionInterval(idx, idx); } addCount = values.length; return true; } catch (UnsupportedFlavorException | IOException ex) { LOG.error(ex.getMessage(), ex); return false; } }
Example 11
Source File: RedditExtractorUI.java From wandora with GNU General Public License v3.0 | 5 votes |
private void populateSubredditSearch() { subredditSearchSubmit.setText("Searching..."); subredditSearchSubmit.setEnabled(false); final String q = subredditSearchField.getText(); final ParseCallback<JsonNode> callback = new ParseCallback<JsonNode>() { @Override public void run(HttpResponse<JsonNode> response) { subredditPopulationCallback(response); } @Override protected void error(Exception e, String body) { DefaultListModel model = new DefaultListModel(); model.add(0, e.getMessage()); subredditResList.setModel(model); subredditSearchSubmit.setText("Search"); subredditSearchSubmit.setEnabled(true); } }; SwingUtilities.invokeLater( new Runnable() { public void run() { AbstractRedditExtractor.getSubreddits(q, callback); } } ); }
Example 12
Source File: PrefManager.java From tda with GNU Lesser General Public License v2.1 | 5 votes |
/** * generate the default filter set. */ private DefaultListModel getPredefinedFilters() { Filter newFilter = new Filter("System Thread Exclusion Filter", ".*at\\s.*", Filter.HAS_IN_STACK_RULE, true, false, false); DefaultListModel filters = new DefaultListModel(); filters.ensureCapacity(2); filters.add(0, newFilter); newFilter = new Filter("Idle Threads Filter", "", Filter.SLEEPING_RULE, true, true, false); filters.add(1, newFilter); return(filters); }
Example 13
Source File: BreakpointNestedGroupsDialog.java From netbeans with Apache License 2.0 | 5 votes |
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed int[] indexes = displayedGroupsList.getSelectedIndices(); DefaultListModel availableModel = (DefaultListModel) availableGroupsList.getModel(); DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel(); int at = availableModel.getSize(); for (int i = indexes.length - 1; i >= 0; i--) { Object element = displayedModel.remove(indexes[i]); availableModel.add(at, element); } }
Example 14
Source File: QFixMessengerFrame.java From quickfix-messenger with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void updateRecentList(Message recentMsg) { if ("Free Text".equals(recentMsg.getName())) { return; } String key = frame.activeDictionary.getFullVersion(); Map<String, DefaultListModel<Message>> tmpMap = frame.recentMessagesMap; DefaultListModel<Message> tmpListModel; if (tmpMap.containsKey(key)) { tmpListModel = tmpMap.get(key); if (tmpListModel.contains(recentMsg)) { tmpListModel.remove(tmpListModel.indexOf(recentMsg)); tmpListModel.add(0, recentMsg); } else { tmpListModel.add(0, recentMsg); } } else { tmpListModel = new DefaultListModel<Message>(); tmpListModel.add(0, recentMsg); tmpMap.put(key, tmpListModel); } frame.recentMessagesList.setModel(tmpMap.get(key)); }
Example 15
Source File: WebClasspathPanel.java From netbeans with Apache License 2.0 | 5 votes |
public WebClasspathPanel(boolean isWizard) { initComponents(); jTextArea1.setBackground(getBackground()); listModel = new DefaultListModel(); listModel.add(0,JAVA_SOURCES_CLASSPATH); classpath.setModel(listModel); if (!isWizard) { jTextArea1.setText(org.openide.util.NbBundle.getMessage(WebClasspathPanel.class, "LBL_ClasspathPanel_Explanation")); } }
Example 16
Source File: SliderTester.java From swing_library with MIT License | 5 votes |
private static JComponent getInner3() { DefaultListModel<String> model = new DefaultListModel<String>(); model.add(0, "Steve Jobs"); JList<String> list = new JList<String>(); list.setModel(model); return list; }
Example 17
Source File: RedditExtractorUI.java From wandora with GNU General Public License v3.0 | 5 votes |
private void populateThreadSearch() { threadSearchSubmit.setText("Searching..."); threadSearchSubmit.setEnabled(false); final String q = threadSearchField.getText(); final ParseCallback<JsonNode> callback = new ParseCallback<JsonNode>() { @Override public void run(HttpResponse<JsonNode> response) { threadPopulationCallback(response); } @Override protected void error(Exception e, String body) { DefaultListModel model = new DefaultListModel(); model.add(0, e.getMessage()); threadResList.setModel(model); threadSearchSubmit.setText("Search"); threadSearchSubmit.setEnabled(true); } }; SwingUtilities.invokeLater( new Runnable() { public void run() { AbstractRedditExtractor.getSubmissions(q, callback); } } ); }
Example 18
Source File: SliderTester.java From swing_library with MIT License | 5 votes |
private static JComponent getInner1() { DefaultListModel<String> model = new DefaultListModel<String>(); model.add(0, "Bill Gates"); model.add(1, "Steven Spielberg"); JList<String> list = new JList<String>(); list.setModel(model); return list; }
Example 19
Source File: ListTransferHandler.java From marathonv5 with Apache License 2.0 | 5 votes |
protected void importString(JComponent c, String str) { JList target = (JList) c; DefaultListModel listModel = (DefaultListModel) target.getModel(); int index = target.getSelectedIndex(); // Prevent the user from dropping data back on itself. // For example, if the user is moving items #4,#5,#6 and #7 and // attempts to insert the items after item #5, this would // be problematic when removing the original items. // So this is not allowed. if (indices != null && index >= indices[0] - 1 && index <= indices[indices.length - 1]) { indices = null; return; } int max = listModel.getSize(); if (index < 0) { index = max; } else { index++; if (index > max) { index = max; } } addIndex = index; String[] values = str.split("\n"); addCount = values.length; for (String value : values) { listModel.add(index++, value); } }
Example 20
Source File: QuantitySelectionPanel.java From opensim-gui with Apache License 2.0 | 4 votes |
public QuantitySelectionPanel(JPlotterQuantitySelector jPlotterQuantitySelectorSingle, PlotterSourceInterface source, String filterRegex, boolean isDomain) { this.jPlotterQuantitySelectorSingle = jPlotterQuantitySelectorSingle; this.isDomain=isDomain; Storage nextStorage = source.getStorage(); ArrayStr columnLabels = nextStorage.getColumnLabels(); int numEntries = columnLabels.getSize(); // make a JList embedded in a ScrollPane and add entries to it //final JPopupMenu p = new JPopupMenu(); DefaultListModel listModel = new DefaultListModel(); int k = 0; if (isDomain && source instanceof PlotterSourceMotion){ listModel.add(k, source.getStorage().getName()); k++; } for (int j = 0; j < columnLabels.getSize(); j++){ final String columnName = columnLabels.getitem(j); if (Pattern.matches(filterRegex, columnName)){ listModel.add(k, columnName); k++; } } final JList list = new JList(listModel); if (this.jPlotterQuantitySelectorSingle.isDomain) list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); else list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { Object obj = e.getSource(); JList lsm = (JList)e.getSource(); // Documentation says it's ListSlectionModel!' int firstIndex = e.getFirstIndex(); int lastIndex = e.getLastIndex(); boolean isAdjusting = e.getValueIsAdjusting(); if (lsm.isSelectionEmpty()) { selected=null; } else { // Find out which indexes are selected. int[] allSelected = lsm.getSelectedIndices(); selected = new String[allSelected.length]; for (int i = 0; i < allSelected.length; i++) { selected[i] = (String) lsm.getModel().getElementAt(allSelected[i]); } } } }); // SelectionListener list.setVisibleRowCount(10); final JScrollPane ext = new JScrollPane(list); this.add(ext); }