本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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
);
}
示例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;
}
示例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;
}
示例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);
}
});
}
示例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);
}
示例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;
}