本文整理汇总了Java中javax.swing.tree.TreeNode.getIndex方法的典型用法代码示例。如果您正苦于以下问题:Java TreeNode.getIndex方法的具体用法?Java TreeNode.getIndex怎么用?Java TreeNode.getIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeNode
的用法示例。
在下文中一共展示了TreeNode.getIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildAfter
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns the child in this node's child array that immediately follows
* <code>aChild</code>, which must be a child of this node. If
* <code>aChild</code> is the last child, returns null. This method performs
* a linear search of this node's children for <code>aChild</code> and is
* O(n) where n is the number of children; to traverse the entire array of
* children, use an enumeration instead.
*
* @param parent
* @param aChild
* @see #children
* @exception IllegalArgumentException if <code>aChild</code> is null or is
* not a child of this node
* @return the child of this node that immediately follows
* <code>aChild</code>
*/
public TreeNode getChildAfter(TreeNode parent, TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
int index = parent.getIndex(aChild); // linear search
if (index == -1) {
throw new IllegalArgumentException("node is not a child");
}
if (index < parent.getChildCount() - 1) {
return parent.getChildAt(index + 1);
} else {
return null;
}
}
示例2: getChildBefore
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns the child in this node's child array that immediately precedes
* <code>aChild</code>, which must be a child of this node. If
* <code>aChild</code> is the first child, returns null. This method
* performs a linear search of this node's children for <code>aChild</code>
* and is O(n) where n is the number of children.
*
* @param parent
* @param aChild
* @exception IllegalArgumentException if <code>aChild</code> is null or is
* not a child of this node
* @return the child of this node that immediately precedes
* <code>aChild</code>
*/
public TreeNode getChildBefore(TreeNode parent, TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
int index = parent.getIndex(aChild); // linear search
if (index == -1) {
throw new IllegalArgumentException("argument is not a child");
}
if (index > 0) {
return parent.getChildAt(index - 1);
} else {
return null;
}
}
示例3: canMoveUp
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public boolean canMoveUp(GenericTreeModel<T> model, T node)
{
TreeNode parent = node.getParent();
if( parent == null )
{
return false;
}
else
{
int index = parent.getIndex(node);
return index > 0 || parent.getParent() != null;
}
}
示例4: canMoveDown
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public boolean canMoveDown(GenericTreeModel<T> model, T node)
{
TreeNode parent = node.getParent();
if( parent == null )
{
return false;
}
else
{
int index = parent.getIndex(node);
return index < parent.getChildCount() - 1 || parent.getParent() != null;
}
}
示例5: treeContains
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private boolean treeContains(TreeNode root, TreeNode node) {
if (root.getIndex(node) != -1) {
return true;
}
for (int i = 0; i < root.getChildCount(); i++) {
if (treeContains(root.getChildAt(i), node)) {
return true;
}
}
return false;
}