javax.swing.tree.DefaultTreeModel#insertNodeInto ( )源码实例Demo

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

源代码1 项目: dragonwell8_jdk   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码2 项目: TencentKona-8   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码3 项目: jdk8u60   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码4 项目: openjdk-jdk9   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码5 项目: jdk8u-jdk   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码6 项目: hottub   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码7 项目: openjdk-8   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码8 项目: pumpernickel   文件: AquaLocationSourceList.java
public AquaLocationSourceList(LocationHistory directoryStack,
		GraphicCache graphicCache) {
	super(new DefaultTreeModel(new DefaultMutableTreeNode("root")));

	treeModel = (DefaultTreeModel) getModel();
	root = (DefaultMutableTreeNode) treeModel.getRoot();

	this.directoryStack = directoryStack;
	this.graphicCache = graphicCache;

	treeModel.insertNodeInto(devices, root, 0);
	treeModel.insertNodeInto(places, root, 1);
	addTreeSelectionListener(treeSelectionListener);
	directoryStack.addChangeListener(directoryStackListener);
	setExpandsSelectedPaths(true);
	setCellRenderer(new SourceListLocationRenderer(graphicCache, this));
	getSelectionModel().setSelectionMode(
			TreeSelectionModel.SINGLE_TREE_SELECTION);
	setUI(new SourceListTreeUI(this));

	expandPath(new TreePath(devices.getPath()));
	expandPath(new TreePath(places.getPath()));
}
 
源代码9 项目: jclic   文件: Editor.java
public boolean moveToIndex(int index, boolean updateSelection) {
  boolean result = false;
  DefaultTreeModel model = getTreeModel();
  Editor p = getEditorParent();
  if (p != null && model != null) {
    index = Math.min(Math.max(0, index), p.getChildCount());
    if (index != p.getIndex(this)) {
      p.setModified(true);
      model.removeNodeFromParent(this);
      model.insertNodeInto(this, p, index);
      result = true;
      if (updateSelection)
        select();
    }
  }
  return result;
}
 
源代码10 项目: jdk8u-jdk   文件: Test8015926.java
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
源代码11 项目: snap-desktop   文件: CatalogTreeUtils.java
public static void appendCatalogNode(MutableTreeNode parentNode, DefaultTreeModel treeModel, InvCatalogRef catalogRef) {
    final DefaultMutableTreeNode catalogNode = new DefaultMutableTreeNode(catalogRef.getName());
    final String catalogPath = catalogRef.getURI().toASCIIString();
    final CatalogNode opendapNode = new CatalogNode(catalogPath, catalogRef);
    opendapNode.setCatalogUri(catalogPath);
    catalogNode.add(new DefaultMutableTreeNode(opendapNode));
    treeModel.insertNodeInto(catalogNode, parentNode, parentNode.getChildCount());
}
 
源代码12 项目: consulo   文件: InspectionRVContentProvider.java
protected static void add(@Nullable final DefaultTreeModel model, final InspectionTreeNode child, final InspectionTreeNode parent) {
  if (model == null) {
    insertByIndex(child, parent);
  }
  else {
    if (parent.getIndex(child) < 0) {
      model.insertNodeInto(child, parent, child.getParent() == parent ? parent.getChildCount() - 1 : parent.getChildCount());
    }
  }
}
 
源代码13 项目: desktop   文件: SettingsDialog.java
public void addProfileToTree(Profile profile, boolean selectRow) {
    // Panels
    ProfilePanel profilePanel = new ProfilePanel(profile);
    RepositoryPanel repoPanel = new RepositoryPanel(profile);
    FoldersPanel foldersPanel = new FoldersPanel(profile);
    
    profilePanel.load();
    repoPanel.load();
    foldersPanel.load();

    // Add to tree
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

    DefaultMutableTreeNode profileNode = new DefaultMutableTreeNode(new ShowPanelTreeItem(profile.getName(), "profile", profilePanel));

    profileNode.add(new DefaultMutableTreeNode(new ShowPanelTreeItem(resourceBundle.getString("sd_remote_storage"), "repository", repoPanel)));
    profileNode.add(new DefaultMutableTreeNode(new ShowPanelTreeItem(resourceBundle.getString("sd_sync_folders"), "folders", foldersPanel)));
    
    model.insertNodeInto(profileNode, root, root.getChildCount() - 1);

    if (selectRow) {
        int profileNodeIndex = tree.getRowForPath(new TreePath(profileNode.getPath()));

        tree.expandRow(profileNodeIndex);
        tree.setSelectionRow(profileNodeIndex);
    }
}
 
源代码14 项目: openjdk-jdk9   文件: LastNodeLowerHalfDrop.java
@Override
public boolean importData(TransferHandler.TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    // Extract transfer data.
    DefaultMutableTreeNode[] nodes = null;
    try {
        Transferable t = support.getTransferable();
        nodes = (DefaultMutableTreeNode[]) t.getTransferData(nodesFlavor);
    } catch (UnsupportedFlavorException ufe) {
        System.out.println("UnsupportedFlavor: " + ufe.getMessage());
    } catch (java.io.IOException ioe) {
        System.out.println("I/O error: " + ioe.getMessage());
    }
    // Get drop location info.
    JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
    int childIndex = dl.getChildIndex();
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode)
            dest.getLastPathComponent();
    JTree tree = (JTree) support.getComponent();
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    // Configure for drop mode.
    int index = childIndex;    // DropMode.INSERT
    if (childIndex == -1) {     // DropMode.ON
        index = parent.getChildCount();
    }
    // Add data to model.
    for (DefaultMutableTreeNode node : nodes) {
        model.insertNodeInto(node, parent, index++);
    }
    return true;
}
 
源代码15 项目: consulo   文件: GroupNode.java
void addTargetsNode(@Nonnull Node node, @Nonnull DefaultTreeModel treeModel) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  int index;
  synchronized (this) {
    index = getNodeInsertionIndex(node, getSwingChildren());
    myChildren.add(index, node);
  }
  treeModel.insertNodeInto(node, this, index);
}
 
源代码16 项目: jsonde   文件: DependencyReport.java
private void createTree(
        Map<Long, Set<Long>> dependencies,
        DefaultTreeModel dependencyTreeModel,
        MutableTreeNode parent,
        Set<Long> codeSourceIds,
        Set<Long> shownSourceIds) {

    int i = 0;

    for (Long codeSourceId : codeSourceIds) {

        try {

            CodeSource codeSource = DaoFactory.getCodeSourceDao().get(codeSourceId);

            MutableTreeNode dependencyNode = new DefaultMutableTreeNode(codeSource.getSource());
            dependencyTreeModel.insertNodeInto(dependencyNode, parent, i);

            if (!shownSourceIds.contains(codeSourceId)) {
                shownSourceIds.add(codeSourceId);
                createTree(dependencies, dependencyTreeModel, dependencyNode, dependencies.get(codeSourceId), shownSourceIds);
            }

        } catch (DaoException e) {
            Main.getInstance().processException(e);
        }

        i++;

    }

}
 
源代码17 项目: consulo   文件: ShelvedChangesViewManager.java
private TreeModel buildChangesModel() {
  myRoot = new DefaultMutableTreeNode(ROOT_NODE_VALUE);   // not null for TreeState matching to work
  DefaultTreeModel model = new DefaultTreeModel(myRoot);
  final List<ShelvedChangeList> changeLists = new ArrayList<ShelvedChangeList>(myShelveChangesManager.getShelvedChangeLists());
  Collections.sort(changeLists, ChangelistComparator.getInstance());
  if (myShelveChangesManager.isShowRecycled()) {
    ArrayList<ShelvedChangeList> recycled =
            new ArrayList<ShelvedChangeList>(myShelveChangesManager.getRecycledShelvedChangeLists());
    Collections.sort(recycled, ChangelistComparator.getInstance());
    changeLists.addAll(recycled);
  }
  myMoveRenameInfo.clear();

  for(ShelvedChangeList changeList: changeLists) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(changeList);
    model.insertNodeInto(node, myRoot, myRoot.getChildCount());

    final List<Object> shelvedFilesNodes = new ArrayList<Object>();
    List<ShelvedChange> changes = changeList.getChanges(myProject);
    for(ShelvedChange change: changes) {
      putMovedMessage(change.getBeforePath(), change.getAfterPath());
      shelvedFilesNodes.add(change);
    }
    List<ShelvedBinaryFile> binaryFiles = changeList.getBinaryFiles();
    for(ShelvedBinaryFile file: binaryFiles) {
      putMovedMessage(file.BEFORE_PATH, file.AFTER_PATH);
      shelvedFilesNodes.add(file);
    }
    Collections.sort(shelvedFilesNodes, ShelvedFilePatchComparator.getInstance());
    for (int i = 0; i < shelvedFilesNodes.size(); i++) {
      final Object filesNode = shelvedFilesNodes.get(i);
      final DefaultMutableTreeNode pathNode = new DefaultMutableTreeNode(filesNode);
      model.insertNodeInto(pathNode, node, i);
    }
  }
  return model;
}
 
源代码18 项目: java-swing-tips   文件: MainPanel.java
@Override public void drop(DropTargetDropEvent dtde) {
  // System.out.println("drop");
  // if (!isWebStart()) {
  //   try {
  //     draggingObject = dtde.getTransferable().getTransferData(FLAVOR);
  //   } catch (Exception ex) {
  //     rejectDrag(dtde);
  //     return;
  //   }
  // } else {
  //   draggingObject = getSelectionPath().getLastPathComponent();
  // }
  Object draggingObject = getSelectionPath().getLastPathComponent();
  Point pt = dtde.getLocation();
  TreePath path = getPathForLocation(pt.x, pt.y);
  if (Objects.isNull(path) || !(draggingObject instanceof MutableTreeNode)) {
    dtde.dropComplete(false);
    return;
  }
  // System.out.println("drop path is " + path);
  MutableTreeNode draggingNode = (MutableTreeNode) draggingObject;
  DefaultMutableTreeNode targetNode = (DefaultMutableTreeNode) path.getLastPathComponent();
  if (targetNode.equals(draggingNode)) {
    // Cannot move the node to the node itself
    dtde.dropComplete(false);
    return;
  }
  dtde.acceptDrop(DnDConstants.ACTION_MOVE);

  DefaultTreeModel model = (DefaultTreeModel) getModel();
  model.removeNodeFromParent(draggingNode);

  TreeNode parent = targetNode.getParent();
  if (parent instanceof MutableTreeNode && targetNode.isLeaf()) {
    model.insertNodeInto(draggingNode, (MutableTreeNode) parent, parent.getIndex(targetNode));
  } else {
    model.insertNodeInto(draggingNode, targetNode, targetNode.getChildCount());
  }
  dtde.dropComplete(true);

  dropTargetNode = null;
  draggedNode = null;
  repaint();
}
 
源代码19 项目: osp   文件: LibraryTreePanel.java
/**
 * Inserts a child into a parent node at a specified index.
 *
 * @param child the child node
 * @param parent the parent node
 * @param index the index
 * @return true if added
 */
protected boolean insertChildAt(final LibraryTreeNode child, LibraryTreeNode parent, int index) {
	if (tree==null || parent.getChildCount()<index) return false;
	DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
	model.insertNodeInto(child, parent, index);  	
  return true;
}
 
源代码20 项目: jsonde   文件: DependencyReport.java
public JComponent generateReport() {

        Map<Long, Set<Long>> dependencies = DaoFactory.getReportDao().getDependencies();

        JTree dependencyTree = new JTree();

        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Dependency tree");
        DefaultTreeModel dependencyTreeModel = new DefaultTreeModel(rootNode);

        int i = 0;

        for (Long codeSourceId : dependencies.keySet()) {

            try {

                CodeSource codeSource = DaoFactory.getCodeSourceDao().get(codeSourceId);

                MutableTreeNode dependencyNode = new DefaultMutableTreeNode(codeSource.getSource());
                dependencyTreeModel.insertNodeInto(dependencyNode, rootNode, i);

                createTree(
                        dependencies,
                        dependencyTreeModel,
                        dependencyNode,
                        dependencies.get(codeSourceId),
                        new LinkedHashSet<Long>(Arrays.asList(codeSourceId)));

            } catch (DaoException e) {
                Main.getInstance().processException(e);
            }

            i++;

        }

        dependencyTree.setModel(dependencyTreeModel);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setViewportView(dependencyTree);

        return scrollPane;
    }