本文整理汇总了Java中javax.swing.JTree.expandRow方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.expandRow方法的具体用法?Java JTree.expandRow怎么用?Java JTree.expandRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.expandRow方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: manipulateJTree
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* This method aids in the creation of the JTrees which are used to add in
* the JTabbedPane component
*
* @param top
* - input to the JTree which will be formatted for display
* @return JTree which will be used for adding to the root of a pane
*/
private JTree manipulateJTree(final DefaultMutableTreeNode top) {
final JTree resultsTree = new JTree(top) {
private static final long serialVersionUID = 1748421292182815368L;
@Override
public Insets getInsets() {
return new Insets(5, 5, 5, 5);
}
};
resultsTree.setRootVisible(false);
resultsTree.setShowsRootHandles(true);
if (resultsTree.getRowCount() > 0) {
resultsTree.expandRow(0);
}
return resultsTree;
}
示例2: restoreLastExpandedPaths
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Expand all the path from the given expandedPaths and the given tree
*
* @param expandedPaths
* - the paths to expand
* @param tree
* - the tree on which the paths has to be expanded
*/
public static void restoreLastExpandedPaths(Enumeration<TreePath> expandedPaths, JTree tree) {
if (expandedPaths != null) {
List<TreePath> paths = Collections.list(expandedPaths);
for (int i = 0; i < tree.getRowCount(); i++) {
TreePath currentPath = tree.getPathForRow(i);
String currentStringPath = TreeFormatter.getStringPath(currentPath);
for (TreePath treePath : paths) {
String stringTreePahr = TreeFormatter.getStringPath(treePath);
if (currentStringPath.equals(stringTreePahr)) {
tree.expandRow(i);
}
}
}
}
}
示例3: selectNextPrev
import javax.swing.JTree; //导入方法依赖的package包/类
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);
if (isQuery) {
CheckNodeListener.findInSource(node);
} else {
CheckNodeListener.openDiff(node);
}
}
示例4: selectNextPrev
import javax.swing.JTree; //导入方法依赖的package包/类
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);
}
示例5: expandPaths
import javax.swing.JTree; //导入方法依赖的package包/类
public static void expandPaths(JTree tree, ArrayList<String> paths_expanded) {
for(int i = 0; i < tree.getRowCount(); i++) {
TreePath tp = tree.getPathForRow(i);
if(paths_expanded.contains(tp.toString())) {
tree.expandRow(i);
}
}
}
示例6: expandAllNodes
import javax.swing.JTree; //导入方法依赖的package包/类
private void expandAllNodes(JTree tree, int startingIndex, int rowCount){
for (int i=startingIndex;i<rowCount;++i)
tree.expandRow(i);
if (tree.getRowCount()!=rowCount)
expandAllNodes(tree, rowCount, tree.getRowCount());
}
示例7: getTreeCellRendererComponent
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Renderer class
*/
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean isSelected,
boolean expanded,
boolean leaf, int row,
boolean hasFocus) {
CorefTreeNode userObject = (CorefTreeNode) value;
label.setText(userObject.toString());
this.setSize(label.getWidth(),
label.getFontMetrics(label.getFont()).getHeight() * 2);
tree.expandRow(row);
if (userObject.getType() == CorefTreeNode.ROOT_NODE || userObject.getType() ==
CorefTreeNode.ANNOTSET_NODE) {
this.setBackground(Color.white);
this.check.setVisible(false);
return this;
}
else {
this.setBackground(currentColors.get(userObject.toString()));
check.setVisible(true);
check.setBackground(Color.white);
}
// if node should be selected
boolean selected = currentSelections.get(userObject.toString()).
booleanValue();
check.setSelected(selected);
return this;
}
示例8: expandAllNodes
import javax.swing.JTree; //导入方法依赖的package包/类
private void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
for (int i = startingIndex; i < rowCount; ++i) {
tree.expandRow(i);
}
if (tree.getRowCount() != rowCount) {
expandAllNodes(tree, rowCount, tree.getRowCount());
}
}
示例9: expandTree
import javax.swing.JTree; //导入方法依赖的package包/类
private void expandTree(JTree tree) {
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel()
.getRoot();
Enumeration e = root.breadthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (node.isLeaf()) {
continue;
}
int row = tree.getRowForPath(new TreePath(node.getPath()));
tree.expandRow(row);
}
}
示例10: createTreePane
import javax.swing.JTree; //导入方法依赖的package包/类
public JScrollPane createTreePane() {
// new tree
root = new DefaultMutableTreeNode("Root");
tree = new JTree(root);
tree.setEditable(false);
// click tree
tree.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if (selPath != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent();
if (node.isLeaf()) {
String type = (String) node.getUserObject();
String strpar = node.getParent().toString();
String strcur = node.toString();
String selectedObjectParent = strpar;
selectedObject = strpar +"." + strcur;
if (console.wMode == HMLP_Console.windowMode.SELECT_DB){
console.insertTextOut("The database \"" + selectedObject +"\" was selected.");
} else if (console.wMode == HMLP_Console.windowMode.EDIT_DB){
} else if (console.wMode == HMLP_Console.windowMode.ADD_PARENTS){
console.insertTextOut("The node \"" + selectedObject +"\" was selected.");
} else if (console.wMode == windowMode.JOIN_RELATIONS) {
} else if (console.wMode == HMLP_Console.windowMode.ADD_CLD){
console.insertTextOut("The node \"" + selectedObject +"\" was selected.");
} else if (console.wMode == windowMode.LEARNING) {
} else if (console.wMode == windowMode.EVALUATION) {
}
}
}
}
});
// Expand all
for (int i = 0; i < tree.getRowCount(); i++)
tree.expandRow(i);
return new JScrollPane(tree);
}
示例11: createTreePane
import javax.swing.JTree; //导入方法依赖的package包/类
public JScrollPane createTreePane() {
// new tree
root = new DefaultMutableTreeNode("Root");
tree = new JTree(root);
tree.setEditable(false);
// click tree
tree.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if (selPath != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent();
if (node.isLeaf()) {
TreePath[] threePaths = tree.getSelectionPaths();
selectedObjects.clear();
for (TreePath tp: threePaths){
DefaultMutableTreeNode eachNode = (DefaultMutableTreeNode) tp.getLastPathComponent();
String strpar = eachNode.getParent().toString();
String str = strpar + "." + eachNode.toString();
selectedObjects.add(str);
}
// String type = (String) node.getUserObject();
// String str2 = node.toString();
// String strpar = node.getParent().toString();
// selectedObject = str2;
if (console.wMode == HMLP_Console.windowMode.SELECT_DB){
console.insertTextOut("The database \"" + selectedObjects +"\" was selected.");
} else if (console.wMode == HMLP_Console.windowMode.EDIT_DB){
} else if (console.wMode == HMLP_Console.windowMode.ADD_PARENTS){
console.insertTextOut("The node \"" + selectedObjects +"\" was selected.");
} else if (console.wMode == windowMode.JOIN_RELATIONS) {
} else if (console.wMode == HMLP_Console.windowMode.ADD_CLD){
console.insertTextOut("The CLD \"" + selectedObjects +"\" was selected.");
} else if (console.wMode == windowMode.LEARNING) {
} else if (console.wMode == windowMode.EVALUATION) {
}
}
}
}
});
// Expand all
for (int i = 0; i < tree.getRowCount(); i++)
tree.expandRow(i);
return new JScrollPane(tree);
}
示例12: expandAllNodes
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Expands all the nodes from the tree
*
* @param tree
* - tree rows to expand
* @param startingIndex
* - starting row index
* @param rowCount
* - end row index
*/
public static void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
for (int i = startingIndex; i < rowCount; ++i) {
tree.expandRow(i);
}
if (tree.getRowCount() != rowCount) {
expandAllNodes(tree, rowCount, tree.getRowCount());
}
}