javax.swing.DefaultListModel#remove ( )源码实例Demo

下面列出了javax.swing.DefaultListModel#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: marathonv5   文件: ListTransferHandler.java
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;
}
 
源代码2 项目: netbeans   文件: CodeCompletionPanel.java
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);
}
 
/**
 * 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;
}
 
源代码4 项目: jeveassets   文件: ShowToolSettingsPanel.java
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;
}
 
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;
}
 
源代码6 项目: magarena   文件: ClassPathFormImpl.java
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());
	}
}
 
源代码7 项目: netbeans   文件: SelectRootsPanel.java
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]);
    }
}
 
源代码8 项目: netbeans   文件: SelectRootsPanel.java
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);
}
 
源代码9 项目: netbeans   文件: SelectRootsPanel.java
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);
}
 
源代码10 项目: PyramidShader   文件: ClassPathFormImpl.java
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());
	}
}
 
源代码11 项目: netbeans   文件: UseSpecificCatchCustomizer.java
private void removeSelected(JList list, String prefKey) {
    DefaultListModel m = (DefaultListModel)list.getModel();
    while (!list.isSelectionEmpty()) {
        m.remove(list.getSelectionModel().getLeadSelectionIndex());
    }
    updatePreference(list, prefKey);
}
 
源代码12 项目: netbeans   文件: CustomizerCompile.java
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);
    }
}
 
源代码13 项目: netbeans   文件: CodeCompletionPanel.java
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);
}
 
源代码14 项目: quickfix-messenger   文件: QFixMessengerFrame.java
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));
}
 
源代码15 项目: netbeans   文件: EarProjectPropertiesTest.java
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);
}
 
源代码16 项目: netbeans   文件: BreakpointNestedGroupsDialog.java
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);
    }
}
 
源代码17 项目: netbeans   文件: BreakpointNestedGroupsDialog.java
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);
    }
}
 
源代码18 项目: iBioSim   文件: GCM2SBMLEditorTest.java
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();
}
 
源代码19 项目: javamoney-examples   文件: CSVColumnPanel.java
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();
    }
  }
}
 
源代码20 项目: beast-mcmc   文件: ClassPathFormImpl.java
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());
	}
}