Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#removeFromParent()

The following examples show how to use javax.swing.tree.DefaultMutableTreeNode#removeFromParent() . 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: MyTree.java    From myqq with MIT License 6 votes vote down vote up
/**
 * 删除树里面的某个好友
 */
public void deleteFriend(String groupName,String friendName)
{
	DefaultMutableTreeNode root=(DefaultMutableTreeNode) treeModel.getRoot();
	for(int i=0;i<root.getChildCount();i++)
	{
		if(root.getChildAt(i).toString().startsWith(groupName))
		{
			for(int j=0;j<root.getChildAt(i).getChildCount();j++)
			{
				if(root.getChildAt(i).getChildAt(j).toString().startsWith(friendName))
				{
					System.out.println(root.getChildAt(i).getChildAt(j));
					DefaultMutableTreeNode node=(DefaultMutableTreeNode)root.getChildAt(i).getChildAt(j);
					node.removeFromParent();
					System.out.println("删除成功!");
				}
				break;
			}
		}
		break;
	}
}
 
Example 2
Source File: Main.java    From myqq with MIT License 5 votes vote down vote up
/**
 * 删除好友
 * @param e
 */
public void deleteFriend(ActionEvent e)
{
	DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
	node.removeFromParent();
	JOptionPane.showMessageDialog(null, "删除好友成功!请关闭并打开当前分组以刷新好友列表!");
}
 
Example 3
Source File: FileSystemInput.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deleteNodes(NodeInterface nodeToTransfer, List<SLDDataInterface> sldDataList) {
    if (sldDataList == null) {
        return;
    }

    if (nodeToTransfer instanceof FileTreeNode) {
        for (SLDDataInterface sldData : sldDataList) {
            String sldFilename = sldData.getSLDFile().getAbsolutePath();

            File file = new File(sldFilename);

            try {
                Files.delete(file.toPath());
            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
            }
        }

        DefaultMutableTreeNode destinationNode = (DefaultMutableTreeNode) nodeToTransfer;

        TreeNode parent = destinationNode.getParent();

        destinationNode.removeFromParent();

        if (treeModel != null) {
            treeModel.reload(parent);
        }
    }
}
 
Example 4
Source File: TypesTreeModel.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Removes a list of given nodes from the model and updates node maps.
 */
private void removeNodes(final List<DefaultMutableTreeNode> nodes) {
  for (final DefaultMutableTreeNode node : nodes) {
    if (node instanceof TypeMemberTreeNode) {
      final TypeMember member = ((TypeMemberTreeNode) node).getTypeMember();
      nestedStructNodes.get(member.getBaseType()).removeAll(memberNodes.get(member));
      memberNodes.remove(member, node);
    }
    node.removeFromParent();
  }
}
 
Example 5
Source File: BurpCertificateStore.java    From SAMLRaider with MIT License 5 votes vote down vote up
/**
 * Deletes a certificate from the store. It can be placed anywhere in the
 * tree.
 * 
 * @param burpCertificate
 *            to remove
 */
public void removeCertificate(BurpCertificate burpCertificate) {
	@SuppressWarnings("unchecked")
	Enumeration<TreeNode> en = rootNode.depthFirstEnumeration();
	while (en.hasMoreElements()) {
		DefaultMutableTreeNode foundNode = (DefaultMutableTreeNode) en.nextElement();
		if (foundNode.getUserObject() instanceof BurpCertificate) {
			if (foundNode.getUserObject() == burpCertificate) {
				foundNode.removeFromParent();
			}
		}
	}
}
 
Example 6
Source File: CategoryModel.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void removedChild(Category child) {
        DefaultMutableTreeNode node = getNode(child);
        if (node != null) {
            node.removeFromParent();
        }
//            getNode(child.getParent()).remove(getNode(child));

        reload();
        categoryTree.expandTree();
    }
 
Example 7
Source File: OutputTreePanel.java    From swing_library with MIT License 5 votes vote down vote up
public void removeInputDefFromTreeModel(InputDef inputDef) {
	System.out.println("REMOVING INPUT DEF id = "
			+ inputDef.getIdentifier());

	DefaultMutableTreeNode nodeToDelete = null;

	Enumeration e = inputNode.breadthFirstEnumeration();

	while (e.hasMoreElements()) {
		DefaultMutableTreeNode element = (DefaultMutableTreeNode) e
				.nextElement();

		Object userObject = element.getUserObject();

		if (userObject instanceof InputDef) {
			InputDef otherInputDef = (InputDef) userObject;

			if (inputDef.equals(otherInputDef)) {
				nodeToDelete = element;
			}
		}
	}
	nodeToDelete.removeFromParent();

	getOutputTree().updateUI();

}
 
Example 8
Source File: TemplateListPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void removeNodeFromParent(DefaultMutableTreeNode node) {
  TreeNode parent = node.getParent();
  int idx = parent.getIndex(node);
  node.removeFromParent();

  ((DefaultTreeModel)myTree.getModel()).nodesWereRemoved(parent, new int[]{idx}, new TreeNode[]{node});
}