當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。