Java 类javax.swing.JTree 实例源码

项目:Neukoelln_SER316    文件:TaskTreeTableCellRenderer.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
项目:SER316-Aachen    文件:TaskTreeTableCellRenderer.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
项目:JAddOn    文件:JTreeUtils.java   
public static JTree updateJTree(JTree tree, TreeArrayList<?> data, ExpandedPaths ep) {
    ArrayList<String> expanded_paths = null;
    TreePath[] paths = null;
    if(ep != null) {
        expanded_paths = ep.getExpandedPaths(tree);
        paths = tree.getSelectionPaths();
    }
    DefaultMutableTreeNode top = getDefaultMutableTreeNodeOfHashMap(data);
    DefaultTreeModel model = new DefaultTreeModel(top);
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    model.reload(root);
    tree.setModel(model);
    if(ep != null) {
        ep.expandPaths(tree, expanded_paths);
        tree.setSelectionPaths(paths);
    }
    return tree;
}
项目:Cognizant-Intelligent-Test-Scripter    文件:JCheckBoxTree.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
        boolean selected, boolean expanded, boolean leaf, int row,
        boolean hasFocus) {
    TreeNode node = (TreeNode) value;
    TreePath tp = new TreePath(getPath(node));
    CheckedNode cn = nodesCheckingState.get(tp);
    checkBox.setIcon(getIcon(value));
    if (cn == null) {
        return this;
    }
    checkBox.setSelected(cn.isSelected);
    checkBox.setText(node.toString());
    checkBox.setOpaque(cn.isSelected && cn.hasChildren && !cn.allChildrenSelected);
    return this;
}
项目:SER316-Munich    文件:TaskTreeTableCellRenderer.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
项目:marathonv5    文件:JavaElementFactory.java   
public static void reset() {
    add(Component.class, JavaElement.class);
    add(JList.class, JListJavaElement.class);
    add(JTabbedPane.class, JTabbedPaneJavaElement.class);
    add(JComboBox.class, JComboBoxJavaElement.class);
    add(JTable.class, JTableJavaElement.class);
    add(JTableHeader.class, JTableHeaderJavaElement.class);
    add(JTree.class, JTreeJavaElement.class);
    add(JToggleButton.class, JToggleButtonJavaElement.class);
    add(JSpinner.class, JSpinnerJavaElement.class);
    add(JProgressBar.class, JProgressBarJavaElement.class);
    add(JSplitPane.class, JSplitPaneJavaElement.class);
    add(JTextComponent.class, JTextComponentJavaElement.class);
    add(EditorContainer.class, JTreeEditingContainerJavaElement.class);
    add(JEditorPane.class, JEditorPaneJavaElement.class);
    add(JMenuItem.class, JMenuItemJavaElement.class);
    add(JSlider.class, JSliderJavaElement.class);
    add(JSpinner.class, JSpinnerJavaElement.class);
    add(DefaultEditor.class, DefaultEditorJavaElement.class);
    add(JColorChooser.class, JColorChooserJavaElement.class);
    add(JFileChooser.class, JFileChooserJavaElement.class);
}
项目:Wilmersdorf_SER316    文件:TaskTreeTableCellRenderer.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
项目:swingspy    文件:SwingSpyPanel.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    if (node.getUserObject() != null) {
        ComponentWrapper userObject = (ComponentWrapper) node.getUserObject();
        if (userObject != null) {
            Component c = userObject.component;
            for (int i = 0; i < cmpClasses.length; i++) {
                Class clazz = cmpClasses[i];
                if (clazz.isAssignableFrom(c.getClass())) {
                    setIcon(cmpIcons[i]);
                    return this;
                }
            }
        }
        setIcon(noneIcon);
    }
    return this;
}
项目:automatic-variants    文件:PackageTree.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    PackageNode item = (PackageNode) value;

    if (hasFocus) {
    item.updateHelp(help, true);
    }

    Component defaultC = defaultR.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    if (item.isDisabled()) {
    defaultC.setForeground(disabledColor);
    }

    if (item.type == PackageNode.Type.VARSET && ((VariantSet)item).spec == null) {
    defaultC.setForeground(Color.RED);
    }

    return defaultC;
}
项目:incubator-netbeans    文件:HintsPanel.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {

            renderer.setBackground(selected ? dr.getBackgroundSelectionColor() : dr.getBackgroundNonSelectionColor());
            renderer.setForeground(selected ? dr.getTextSelectionColor() : dr.getTextNonSelectionColor());
            renderer.setFont(renderer.getFont().deriveFont(Font.PLAIN));
            renderer.setOpaque(true);
            renderer.setEnabled(tree.isEnabled());

            Object data = ((DefaultMutableTreeNode) value).getUserObject();
            if (data instanceof HintCategory) {
                HintCategory cat = ((HintCategory) data);
                renderer.setText(cat.displayName);
            } else if (data instanceof HintMetadata) {
                HintMetadata treeRule = (HintMetadata) data;
                if (treeRule.options.contains(Options.QUERY)) {
                    renderer.setFont(renderer.getFont().deriveFont(Font.ITALIC));
                }
                renderer.setText(treeRule.displayName);

            } else {
                renderer.setText(value.toString());
            }

            return renderer;
        }
项目:jdk8u-jdk    文件:SynthTreeUI.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    if (!useTreeColors && (sel || hasFocus)) {
        SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
                     getUIOfType(getUI(), SynthLabelUI.class),
                           sel, hasFocus, tree.isEnabled(), false);
    }
    else {
        SynthLookAndFeel.resetSelectedUI();
    }
    return super.getTreeCellRendererComponent(tree, value, sel,
                                              expanded, leaf, row, hasFocus);
}
项目:openjdk-jdk10    文件:LastNodeLowerHalfDrop.java   
private boolean haveCompleteNode(JTree tree) {
    int[] selRows = tree.getSelectionRows();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode first = (DefaultMutableTreeNode)
            path.getLastPathComponent();
    int childCount = first.getChildCount();
    // first has children and no children are selected.
    if (childCount > 0 && selRows.length == 1) {
        return false;
    }
    // first may have children.
    for (int i = 1; i < selRows.length; i++) {
        path = tree.getPathForRow(selRows[i]);
        DefaultMutableTreeNode next = (DefaultMutableTreeNode)
                path.getLastPathComponent();
        if (first.isNodeChild(next)) {
            // Found a child of first.
            if (childCount > selRows.length - 1) {
                // Not all children of first are selected.
                return false;
            }
        }
    }
    return true;
}
项目:VASSAL-src    文件:ConfigureTree.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  if (value instanceof DefaultMutableTreeNode) {
    final Configurable c =
      (Configurable) ((DefaultMutableTreeNode) value).getUserObject();
    if (c != null) {
      leaf = c.getAllowableConfigureComponents().length == 0;
      value = (c.getConfigureName() != null ? c.getConfigureName() : "") +
              " [" + getConfigureName(c.getClass()) + "]";
    }
  }

  return super.getTreeCellRendererComponent(
    tree, value, sel, expanded, leaf, row, hasFocus
  );
}
项目:incubator-netbeans    文件:DebuggingViewComponent.java   
/**
 * Store first visible node and its offset. Called when the view is scrolled
 * by the user.
 */
private void storeScrollPosition() {
    JTree tree = getJTree();
    if (tree != null) {
        int scrollTop = mainScrollPane.getViewport().getViewPosition().y;
        int row = tree.getClosestRowForLocation(tree.getRowBounds(0).x + 1,
                scrollTop);
        if (row >= 0) {
            TreePath path = tree.getPathForRow(row);
            if (path != null) {
                int offset = tree.getRowBounds(row).y - scrollTop;
                visibleTreePosition = new VisibleTreePosition(
                        path, offset);
                return;
            }
        } else {
            return;
        }
    }
    visibleTreePosition = null;
}
项目:SER316-Dresden    文件:TaskTreeTableCellRenderer.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row, boolean hasFocus) {
    // if root then just return some component
    // it is not shown anyway
    super.getTreeCellRendererComponent(
            tree, value, selected,
            expanded, leaf, row,
            hasFocus);
    if (value instanceof Project)
        return empty_panel;
    if (!(value instanceof Task))
        return empty_panel;
    Task t = (Task) value; 
    setText(t.getText());
    setToolTipText(t.getDescription());
    setIcon(getStatusIcon(t));
    applyFont(t, this);
    //return getTaskTreeCellRenderer(t, selected, hasFocus);
    return this;
}
项目:openjdk-jdk10    文件:MultiTreeUI.java   
/**
 * Invokes the <code>getPathBounds</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle getPathBounds(JTree a, TreePath b) {
    Rectangle returnValue =
        ((TreeUI) (uis.elementAt(0))).getPathBounds(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).getPathBounds(a,b);
    }
    return returnValue;
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.setScrollsOnExpand(boolean)} through queue
 */
public void setScrollsOnExpand(final boolean b) {
    runMapping(new MapVoidAction("setScrollsOnExpand") {
        @Override
        public void map() {
            ((JTree) getSource()).setScrollsOnExpand(b);
        }
    });
}
项目:openjdk-jdk10    文件:UpdateUIRecursionTest.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                          boolean selected, boolean expanded, boolean leaf,
                          int row, boolean hasFocus)
{
    return renderer.getTreeCellRendererComponent(tree, value, leaf,
                                            expanded, leaf, row, hasFocus);
}
项目:marathonv5    文件:TreeIconDemo2.java   
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
        int row, boolean hasFocus) {

    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (leaf && isTutorialBook(value)) {
        setIcon(tutorialIcon);
        setToolTipText("This book is in the Tutorial series.");
    } else {
        setToolTipText(null); // no tool tip
    }

    return this;
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.expandPath(TreePath)} through queue
 */
public void expandPath(final TreePath treePath) {
    runMapping(new MapVoidAction("expandPath") {
        @Override
        public void map() {
            ((JTree) getSource()).expandPath(treePath);
        }
    });
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.getLastSelectedPathComponent()} through queue
 */
public Object getLastSelectedPathComponent() {
    return (runMapping(new MapAction<Object>("getLastSelectedPathComponent") {
        @Override
        public Object map() {
            return ((JTree) getSource()).getLastSelectedPathComponent();
        }
    }));
}
项目:OpenJSharp    文件:SchemaTreeTraverser.java   
public final Component getTreeCellRendererComponent(JTree tree, Object value,
                                                    boolean selected, boolean expanded, boolean leaf, int row,
                                                    boolean hasFocus) {
    if (value instanceof SchemaTreeNode) {
        SchemaTreeNode stn = (SchemaTreeNode) value;

        this.setValues(null, stn.getCaption(), selected);
        return this;
    }
    throw new IllegalStateException("Unknown node");
}
项目:jdk8u-jdk    文件:MultiTreeUI.java   
/**
 * Invokes the <code>getPathBounds</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public Rectangle getPathBounds(JTree a, TreePath b) {
    Rectangle returnValue =
        ((TreeUI) (uis.elementAt(0))).getPathBounds(a,b);
    for (int i = 1; i < uis.size(); i++) {
        ((TreeUI) (uis.elementAt(i))).getPathBounds(a,b);
    }
    return returnValue;
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.getVisibleRowCount()} through queue
 */
public int getVisibleRowCount() {
    return (runMapping(new MapIntegerAction("getVisibleRowCount") {
        @Override
        public int map() {
            return ((JTree) getSource()).getVisibleRowCount();
        }
    }));
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.fireTreeExpanded(TreePath)} through queue
 */
public void fireTreeExpanded(final TreePath treePath) {
    runMapping(new MapVoidAction("fireTreeExpanded") {
        @Override
        public void map() {
            ((JTree) getSource()).fireTreeExpanded(treePath);
        }
    });
}
项目:OpenJSharp    文件:SynthTreeUI.java   
/**
 * {@inheritDoc}
 */
@Override
protected void paintDropLine(Graphics g) {
    JTree.DropLocation loc = tree.getDropLocation();
    if (!isDropLine(loc)) {
        return;
    }

    Color c = (Color)style.get(paintContext, "Tree.dropLineColor");
    if (c != null) {
        g.setColor(c);
        Rectangle rect = getDropLineRect(loc);
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
    }
}
项目:JAddOn    文件:TreeTransferHandler.java   
public boolean canImport(TransferHandler.TransferSupport support) {
    if(!support.isDrop()) {
        return false;
    }
    support.setShowDropLocation(true);
    if(!support.isDataFlavorSupported(nodesFlavor)) {
        return false;
    }
    // Do not allow a drop on the drag source selections.
    JTree.DropLocation dl =
            (JTree.DropLocation)support.getDropLocation();
    JTree tree = (JTree)support.getComponent();
    int dropRow = tree.getRowForPath(dl.getPath());
    int[] selRows = tree.getSelectionRows();
    for(int i = 0; i < selRows.length; i++) {
        if(selRows[i] == dropRow) {
            return false;
        }
    }
    // Do not allow MOVE-action drops if a non-leaf node is
    // selected unless all of its children are also selected.
    int action = support.getDropAction();
    if(action == MOVE) {
        return haveCompleteNode(tree);
    }
    // Do not allow a non-leaf node to be copied to a level
    // which is less than its source level.
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode target =
        (DefaultMutableTreeNode)dest.getLastPathComponent();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode firstNode =
        (DefaultMutableTreeNode)path.getLastPathComponent();
    if(firstNode.getChildCount() > 0 &&
           target.getLevel() < firstNode.getLevel()) {
        return false;
    }
    return true;
}
项目:marathonv5    文件:JTreeJavaElement.java   
private String getPathText(JTree tree, TreePath path) {
    Object lastPathComponent = path.getLastPathComponent();
    if (lastPathComponent == null) {
        return "";
    }
    return getTextForNodeObject(tree, lastPathComponent);
}
项目:openjdk-jdk10    文件:Test8013571.java   
public static void main(String[] args) {
    DefaultMutableTreeNode root = create("root");
    root.add(create("colors", "blue", "violet", "red", "yellow"));
    root.add(create("sports", "basketball", "soccer", "football", "hockey"));
    root.add(create("food", "hot dogs", "pizza", "ravioli", "bananas"));
    Test8013571 model = new Test8013571(root);
    JTree tree = new JTree(model);
    model.fireTreeChanged(tree);
}
项目:openjdk-jdk10    文件:bug8003830.java   
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
项目:incubator-netbeans    文件:CheckListener.java   
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;

    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;

    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.fireTreeWillCollapse(TreePath)} through queue
 */
public void fireTreeWillCollapse(final TreePath treePath) {
    runMapping(new MapVoidAction("fireTreeWillCollapse") {
        @Override
        public void map() throws ExpandVetoException {
            ((JTree) getSource()).fireTreeWillCollapse(treePath);
        }
    });
}
项目:incubator-netbeans    文件:CheckNodeListener.java   
static void selectNextPrev(final boolean next, boolean isQuery, JTree tree) {
    int[] rows = tree.getSelectionRows();
    int newRow = rows == null || rows.length == 0 ? 0 : rows[0];
    int maxcount = tree.getRowCount();
    CheckNode node;
    do {
        if (next) {
            newRow++;
            if (newRow >= maxcount) {
                newRow = 0;
            }
        } else {
            newRow--;
            if (newRow < 0) {
                newRow = maxcount - 1;
            }
        }
        TreePath path = tree.getPathForRow(newRow);
        node = (CheckNode) path.getLastPathComponent();
        if (!node.isLeaf()) {
            tree.expandRow(newRow);
            maxcount = tree.getRowCount();
        }
    } while (!node.isLeaf());
    tree.setSelectionRow(newRow);
    tree.scrollRowToVisible(newRow);
}
项目:incubator-netbeans    文件:HintsPanelLogic.java   
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {

        if ( e.getSource() instanceof JTree ) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getSelectionPath();

            if ( toggle( path )) {
                e.consume();
            }
        }
    }
}
项目:openjdk-jdk10    文件:SynthTreeUI.java   
/**
 * {@inheritDoc}
 */
@Override
protected void paintDropLine(Graphics g) {
    JTree.DropLocation loc = tree.getDropLocation();
    if (!isDropLine(loc)) {
        return;
    }

    Color c = (Color)style.get(paintContext, "Tree.dropLineColor");
    if (c != null) {
        g.setColor(c);
        Rectangle rect = getDropLineRect(loc);
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
    }
}
项目:myqq    文件:MyTreeIcon.java   
public Component getTreeCellRendererComponent(
                    JTree tree,
                    Object value,
                    boolean sel,
                    boolean expanded,
                    boolean leaf,
                    int row,
                    boolean hasFocus) 
{
    super.getTreeCellRendererComponent(tree, value, sel,expanded,
            leaf, row, hasFocus);
    for(String str:nodeImages)
    {
        String[] temp=str.split(MyTools.SPLIT1);
        if(value.toString().startsWith(temp[0])&&!temp[0].equals(""))//注意Value一定要toString()
        {
             try
{
    //Image grayImage = GrayFilter.createDisabledImage(ImageIO.read(Main.class.getResource(temp[1])));
    if(temp.length==2)//如果是:用户名;图片路径,那么就是好友节点
                //this.setIcon(new ImageIcon(grayImage));
        this.setIcon(MyTools.getIcon(temp[1]));
            else if(temp.length==3)//如果是:用户名;图片路径1;图片路径2,那么表示分组节点,
            {
                if(!expanded)
                    this.setIcon(MyTools.getIcon(temp[1]));
                else 
                    this.setIcon(MyTools.getIcon(temp[2]));
            }
}
catch (Exception e)
{
    e.printStackTrace();
}

        }
    }
    return this;
}
项目:ramus    文件:ModelsPanel.java   
private void init() {
    treeModel.setRoot(createRoot());

    tree = new JTree(treeModel) {
        @Override
        public TreeCellRenderer getCellRenderer() {
            TreeCellRenderer renderer = super.getCellRenderer();
            if (renderer == null)
                return null;
            ((DefaultTreeCellRenderer) renderer).setLeafIcon(new ImageIcon(
                    getClass().getResource("/images/function.png")));
            return renderer;
        }
    };

    tree.setCellRenderer(new Renderer());

    tree.setEditable(true);

    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if ((e.getButton() == MouseEvent.BUTTON1)
                    && (e.getClickCount() == 2)) {
                openDiagram();
            }
        }

    });

    tree.setRootVisible(true);

    JScrollPane pane = new JScrollPane();
    pane.setViewportView(tree);
    this.add(pane, BorderLayout.CENTER);
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.setRowHeight(int)} through queue
 */
public void setRowHeight(final int i) {
    runMapping(new MapVoidAction("setRowHeight") {
        @Override
        public void map() {
            ((JTree) getSource()).setRowHeight(i);
        }
    });
}
项目:openjdk-jdk10    文件:JTreeOperator.java   
/**
 * Maps {@code JTree.getRowForPath(TreePath)} through queue
 */
public int getRowForPath(final TreePath treePath) {
    return (runMapping(new MapIntegerAction("getRowForPath") {
        @Override
        public int map() {
            return ((JTree) getSource()).getRowForPath(treePath);
        }
    }));
}
项目:JAddOn    文件:TreeTransferHandler.java   
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(int i = 0; i < nodes.length; i++) {
        model.insertNodeInto(nodes[i], parent, index++);
    }
    return true;
}