Java Code Examples for javax.swing.DefaultListModel#remove()
The following examples show how to use
javax.swing.DefaultListModel#remove() .
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 void cleanup(JComponent c, boolean remove) { if (remove && indices != null) { JList source = (JList) c; DefaultListModel model = (DefaultListModel) source.getModel(); // If we are moving items around in the same list, we // need to adjust the indices accordingly, since those // after the insertion point have moved. if (addCount > 0) { for (int i = 0; i < indices.length; i++) { if (indices[i] > addIndex) { indices[i] += addCount; } } } for (int i = indices.length - 1; i >= 0; i--) { model.remove(indices[i]); } } indices = null; addCount = 0; addIndex = -1; }
Example 2
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 3
Source File: ShowToolSettingsPanel.java From jeveassets with GNU General Public License v2.0 | 6 votes |
private void cleanup(JComponent c, boolean remove) { if (remove && Objects.nonNull(indices)) { if (addCount > 0) { // https://github.com/aterai/java-swing-tips/blob/master/DragSelectDropReordering/src/java/example/MainPanel.java for (int i = 0; i < indices.length; i++) { if (indices[i] >= addIndex) { indices[i] += addCount; } } } JList<?> source = (JList) c; DefaultListModel<?> model = (DefaultListModel) source.getModel(); for (int i = indices.length - 1; i >= 0; i--) { model.remove(indices[i]); } } indices = null; addCount = 0; addIndex = -1; }
Example 4
Source File: ExtendedJListTransferHandler.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Make sure indices are correct after a move in the list. */ private void cleanup(JComponent c, boolean remove) { if (remove && Objects.nonNull(indices)) { if (addCount > 0) { // https://github.com/aterai/java-swing-tips/blob/master/DragSelectDropReordering/src/java/example/MainPanel.java for (int i = 0; i < indices.length; i++) { if (indices[i] >= addIndex) { indices[i] += addCount; } } } JList source = (JList) c; DefaultListModel model = (DefaultListModel) source.getModel(); for (int i = indices.length - 1; i >= 0; i--) { model.remove(indices[i]); } } indices = null; addCount = 0; addIndex = -1; }
Example 5
Source File: CodeCompletionPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void javaCompletionExcluderDialogOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javaCompletionExcluderDialogOkButtonActionPerformed JList list = getSelectedExcluderList(); String text = javaCompletionExcluderDialogTextField.getText(); DefaultListModel model = (DefaultListModel) list.getModel(); int index = model.size(); if (javaExcluderEditing != null){ // if this was an "edit" rather than "add", then remove the old entry first index = model.indexOf(javaExcluderEditing); model.remove(index); javaExcluderEditing = null; } String[] entries = text.split(","); // NOI18N for (String entry : entries) { // strip zero width spaces entry = entry.replaceAll("\u200B", ""); // NOI18N entry = entry.trim(); if (entry.length() != 0 && entry.matches(JAVA_FQN_REGEX)){ model.insertElementAt(entry, index); index++; } } updateExcluder(list); javaCompletionExcluderDialog2.setVisible(false); javaCompletionExcluderDialogTextField.setText(null); }
Example 6
Source File: ClassPathFormImpl.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent e) { if (_classpathList.isSelectionEmpty() || !MainFrame.getInstance().confirm( Messages.getString("confirmClassPathRemoval"))) { return; } DefaultListModel model = (DefaultListModel) _classpathList.getModel(); while (!_classpathList.isSelectionEmpty()) { model.remove(_classpathList.getSelectedIndex()); } }
Example 7
Source File: UseSpecificCatchCustomizer.java From netbeans with Apache License 2.0 | 5 votes |
private void removeSelected(JList list, String prefKey) { DefaultListModel m = (DefaultListModel)list.getModel(); while (!list.isSelectionEmpty()) { m.remove(list.getSelectionModel().getLeadSelectionIndex()); } updatePreference(list, prefKey); }
Example 8
Source File: CustomizerCompile.java From netbeans with Apache License 2.0 | 5 votes |
private void removeProcessorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeProcessorButtonActionPerformed DefaultListModel model = (DefaultListModel) annotationProcessorsList.getModel(); int[] indices = annotationProcessorsList.getSelectedIndices(); for (int i = indices.length - 1 ; i >= 0 ; i--) { model.remove(indices[i]); } if (!model.isEmpty()) { // Select reasonable item int selectedIndex = indices[indices.length - 1] - indices.length + 1; if (selectedIndex > model.size() - 1) { selectedIndex = model.size() - 1; } annotationProcessorsList.setSelectedIndex(selectedIndex); } }
Example 9
Source File: SelectRootsPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void moveDown(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDown final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel(); final int[] index = sources.getSelectedIndices(); for (int i=index.length-1; i>=0; i--) { final URI toMove = lm.remove(index[i]); lm.add(index[i]+1, toMove); index[i]++; } sources.setSelectedIndices(index); }
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: 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 12
Source File: EarProjectPropertiesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testResolveProjectDependencies() throws Exception { int countBefore = EarProjectProperties.getJarContentAdditional(earProject).size(); DefaultListModel l = earProjectProperties.EAR_CONTENT_ADDITIONAL_MODEL.getDefaultListModel(); l.remove(l.indexOf(getEjbProject())); earProjectProperties.store(); EditableProperties ep = TestUtil.loadProjectProperties(earProject.getProjectDirectory()); String ejbReferenceValue = ep.getProperty(EJB_REFERENCE_EXPECTED_KEY); assertNull("ejb reference should not exist", ejbReferenceValue); String carReferenceValue = ep.getProperty(CAR_REFERENCE_EXPECTED_KEY); assertEquals("car reference should exist", CAR_REFERENCE_EXPECTED_VALUE, carReferenceValue); assertEquals("wrong count of project references", countBefore - 1, EarProjectProperties.getJarContentAdditional(earProject).size()); assertEquals("wrong count of project references", countBefore - 1, earProject.getReferenceHelper().getRawReferences().length); // remove all entries l.clear(); earProjectProperties.store(); assertEquals("wrong count of project references", 0, EarProjectProperties.getJarContentAdditional(earProject).size()); // add new project/module l.addElement(getWebProject()); earProjectProperties.store(); ep = TestUtil.loadProjectProperties(earProject.getProjectDirectory()); ejbReferenceValue = ep.getProperty(EJB_REFERENCE_EXPECTED_KEY); assertNull("ejb reference should not exist", ejbReferenceValue); carReferenceValue = ep.getProperty(CAR_REFERENCE_EXPECTED_KEY); assertNull("car reference should not exist", carReferenceValue); String webReferenceValue = ep.getProperty(WEB_REFERENCE_EXPECTED_KEY); assertEquals("web reference should exist", WEB_REFERENCE_EXPECTED_VALUE, webReferenceValue); assertEquals("wrong count of project references", 1, EarProjectProperties.getJarContentAdditional(earProject).size()); assertEquals("wrong count of project references", 1, earProject.getReferenceHelper().getRawReferences().length); }
Example 13
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 14
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 15
Source File: GCM2SBMLEditorTest.java From iBioSim with Apache License 2.0 | 5 votes |
public void testList() { JFrame frame = new JFrame(); JPanel panel = new JPanel(); DefaultListModel model = new DefaultListModel(); model.addElement("foo"); model.addElement("bar"); JList list = new JList(model); panel.add(list); frame.add(panel); frame.pack(); frame.setVisible(true); System.out.println(); model.remove(1); System.out.println(); }
Example 16
Source File: SelectRootsPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void moveUp(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUp final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel(); final int[] index = sources.getSelectedIndices(); for (int i=0; i< index.length; i++) { final URI toMove = lm.remove(index[i]); lm.add(index[i]-1, toMove); index[i]--; } sources.setSelectedIndices(index); }
Example 17
Source File: SelectRootsPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void remove(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove final DefaultListModel<URI> lm = (DefaultListModel<URI>) sources.getModel(); final int[] index = sources.getSelectedIndices(); for (int i=index.length-1; i>=0; i--) { lm.remove(index[i]); } }
Example 18
Source File: CSVColumnPanel.java From javamoney-examples with Apache License 2.0 | 5 votes |
private void moveColumn(String action) { DefaultListModel model = (DefaultListModel)getList().getModel(); Object object = getList().getSelectedValue(); int index = getList().getSelectedIndex(); if(action.equals(ACTION_DOWN) == true) { ++index; if(index < model.getSize()) { model.remove(index - 1); model.add(index, object); getList().setSelectedIndex(index); storeCSVColumnOrder(); } } else { --index; if(index > -1) { model.remove(index + 1); model.add(index, object); getList().setSelectedIndex(index); storeCSVColumnOrder(); } } }
Example 19
Source File: ClassPathFormImpl.java From beast-mcmc with GNU Lesser General Public License v2.1 | 5 votes |
public void actionPerformed(ActionEvent e) { if (_classpathList.isSelectionEmpty() || !MainFrame.getInstance().confirm( Messages.getString("confirmClassPathRemoval"))) { return; } DefaultListModel model = (DefaultListModel) _classpathList.getModel(); while (!_classpathList.isSelectionEmpty()) { model.remove(_classpathList.getSelectedIndex()); } }
Example 20
Source File: ClassPathFormImpl.java From magarena with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent e) { if (_classpathList.isSelectionEmpty() || !MainFrame.getInstance().confirm( Messages.getString("confirmClassPathRemoval"))) { return; } DefaultListModel model = (DefaultListModel) _classpathList.getModel(); while (!_classpathList.isSelectionEmpty()) { model.remove(_classpathList.getSelectedIndex()); } }