当前位置: 首页>>代码示例>>Java>>正文


Java JTree类代码示例

本文整理汇总了Java中javax.swing.JTree的典型用法代码示例。如果您正苦于以下问题:Java JTree类的具体用法?Java JTree怎么用?Java JTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JTree类属于javax.swing包,在下文中一共展示了JTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
@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;
}
 
开发者ID:igr,项目名称:swingspy,代码行数:22,代码来源:SwingSpyPanel.java

示例2: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
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;
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:21,代码来源:TaskTreeTableCellRenderer.java

示例3: updateJTree

import javax.swing.JTree; //导入依赖的package包/类
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;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:19,代码来源:JTreeUtils.java

示例4: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
@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;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:17,代码来源:JCheckBoxTree.java

示例5: reset

import javax.swing.JTree; //导入依赖的package包/类
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);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:JavaElementFactory.java

示例6: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
@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;
}
 
开发者ID:tstavrianos,项目名称:automatic-variants,代码行数:20,代码来源:PackageTree.java

示例7: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
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;
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:HintsPanel.java

示例8: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
@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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:SynthTreeUI.java

示例9: haveCompleteNode

import javax.swing.JTree; //导入依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:LastNodeLowerHalfDrop.java

示例10: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
@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
  );
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:17,代码来源:ConfigureTree.java

示例11: storeScrollPosition

import javax.swing.JTree; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:DebuggingViewComponent.java

示例12: getPathBounds

import javax.swing.JTree; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:MultiTreeUI.java

示例13: setScrollsOnExpand

import javax.swing.JTree; //导入依赖的package包/类
/**
 * 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);
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:JTreeOperator.java

示例14: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
@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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:UpdateUIRecursionTest.java

示例15: getTreeCellRendererComponent

import javax.swing.JTree; //导入依赖的package包/类
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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:TreeIconDemo2.java


注:本文中的javax.swing.JTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。