本文整理匯總了Java中javax.swing.JTree.getRowForPath方法的典型用法代碼示例。如果您正苦於以下問題:Java JTree.getRowForPath方法的具體用法?Java JTree.getRowForPath怎麽用?Java JTree.getRowForPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.getRowForPath方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: storeScrollPosition
import javax.swing.JTree; //導入方法依賴的package包/類
/**
* Store visible offset of an important node. Called when the view is
* scrolled by ViewRefresher
*
* @param path Path to a node that should stay visible at the same position.
*/
private void storeScrollPosition(TreePath path) {
JTree tree = getJTree();
if (tree != null && path != null) {
int row = tree.getRowForPath(path);
if (row >= 0) {
int scrollTop = mainScrollPane.getViewport().getViewPosition().y;
int offset = tree.getRowBounds(row).y - scrollTop;
visibleTreePosition = new VisibleTreePosition(
path, offset);
return;
} else {
return;
}
}
visibleTreePosition = null;
}
示例2: restoreScrollPosition
import javax.swing.JTree; //導入方法依賴的package包/類
/**
* Restore stored scroll position.
*/
private void restoreScrollPosition(boolean delayScrollWithMarkingDirtyRegion) {
if (visibleTreePosition != null) {
JTree tree = getJTree();
if (tree != null) {
int row = tree.getRowForPath(visibleTreePosition.getPath());
if (row != -1) {
Rectangle bounds = tree.getRowBounds(row);
if (bounds != null) {
int scrollY = bounds.y - visibleTreePosition.getOffset();
JViewport viewport = mainScrollPane.getViewport();
Rectangle rect = viewport.getViewRect();
rect.y = scrollY;
if (!rect.isEmpty()) {
JComponent view = (JComponent) viewport.getView();
if (delayScrollWithMarkingDirtyRegion) {
RepaintManager.currentManager(viewport).addDirtyRegion(
view,
rect.x, rect.x, rect.width, rect.height);
}
ignoreScrollAdjustment = true;
try {
view.scrollRectToVisible(
rect);
} finally {
ignoreScrollAdjustment = false;
}
}
}
}
}
}
}
示例3: RTree
import javax.swing.JTree; //導入方法依賴的package包/類
public RTree(Component source, JSONOMapConfig omapConfig, Point point, IJSONRecorder recorder) {
super(source, omapConfig, point, recorder);
JTree tree = (JTree) source;
if (point != null) {
row = tree.getClosestRowForLocation(point.x, point.y);
} else {
if (tree.isEditing()) {
TreePath editingPath = tree.getEditingPath();
row = tree.getRowForPath(editingPath);
}
}
cellInfo = getTextForNode(tree, row);
}
示例4: canImport
import javax.swing.JTree; //導入方法依賴的package包/類
public boolean canImport(TransferHandler.TransferSupport support) {
if(!support.isDrop()) {
return false;
}
support.setShowDropLocation(true);
if(!support.isDataFlavorSupported(nodesFlavor)) {
return false;
}
// Do not allow a drop on the drag source selections.
JTree.DropLocation dl =
(JTree.DropLocation)support.getDropLocation();
JTree tree = (JTree)support.getComponent();
int dropRow = tree.getRowForPath(dl.getPath());
int[] selRows = tree.getSelectionRows();
for(int i = 0; i < selRows.length; i++) {
if(selRows[i] == dropRow) {
return false;
}
}
// Do not allow MOVE-action drops if a non-leaf node is
// selected unless all of its children are also selected.
int action = support.getDropAction();
if(action == MOVE) {
return haveCompleteNode(tree);
}
// Do not allow a non-leaf node to be copied to a level
// which is less than its source level.
TreePath dest = dl.getPath();
DefaultMutableTreeNode target =
(DefaultMutableTreeNode)dest.getLastPathComponent();
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode firstNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
if(firstNode.getChildCount() > 0 &&
target.getLevel() < firstNode.getLevel()) {
return false;
}
return true;
}
示例5: 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);
}
}
示例6: canImport
import javax.swing.JTree; //導入方法依賴的package包/類
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
if (!support.isDrop()) {
return false;
}
support.setShowDropLocation(true);
if (!support.isDataFlavorSupported(nodesFlavor)) {
return false;
}
// Do not allow a drop on the drag source selections.
JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
JTree tree = (JTree) support.getComponent();
int dropRow = tree.getRowForPath(dl.getPath());
int[] selRows = tree.getSelectionRows();
for (int i = 0; i < selRows.length; i++) {
if (selRows[i] == dropRow) {
return false;
}
}
// Do not allow MOVE-action drops if a non-leaf node is
// selected unless all of its children are also selected.
int action = support.getDropAction();
if (action == MOVE) {
return haveCompleteNode(tree);
}
// Do not allow a non-leaf node to be copied to a level
// which is less than its source level.
TreePath dest = dl.getPath();
DefaultMutableTreeNode target = (DefaultMutableTreeNode)
dest.getLastPathComponent();
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode)
path.getLastPathComponent();
if (firstNode.getChildCount() > 0
&& target.getLevel() < firstNode.getLevel()) {
return false;
}
return true;
}
示例7: adaptContainerStyle
import javax.swing.JTree; //導入方法依賴的package包/類
private void adaptContainerStyle(JTree tree, Object node, boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus, boolean dragging, boolean setForeground) {
SwingTools.setEnabledRecursive(this, tree.isEnabled());
Color fg = null;
Color bg = null;
boolean highlightingEnabled = RapidMinerGUI.getDragHighlighteMode().equals(DragHighlightMode.FULL);
JTree.DropLocation dropLocation = tree.getDropLocation();
if (dropLocation != null && dropLocation.getChildIndex() == -1
&& tree.getRowForPath(dropLocation.getPath()) == row) {
fg = TEXT_SELECTED_COLOR;
bg = SELECTED_COLOR;
} else if (selected && !dragging) {
fg = TEXT_SELECTED_COLOR;
bg = SELECTED_COLOR;
} else {
fg = TEXT_NON_SELECTED_COLOR;
if (highlightingEnabled && dragging) {
bg = ProcessDrawer.INNER_DRAG_COLOR;
} else {
bg = NOT_SELECTED_COLOR;
}
}
if (setForeground) {
nameLabel.setForeground(fg);
attributeLabel.setForeground(fg);
}
this.setBackground(bg);
if (hasFocus) {
this.setBorder(focusBorder);
} else {
if (highlightingEnabled && dragging) {
this.setBorder(draggingNotFocusedBorder);
} else {
this.setBorder(nonFocusBorder);
}
}
}
示例8: getTreeCellRendererComponent
import javax.swing.JTree; //導入方法依賴的package包/類
/**
* Configures the renderer based on the passed in components.
* The value is set from messaging the tree with
* <code>convertValueToText</code>, which ultimately invokes
* <code>toString</code> on <code>value</code>.
* The foreground color is set based on the selection and the icon
* is set based on the <code>leaf</code> and <code>expanded</code>
* parameters.
*/
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel,
boolean expanded,
boolean leaf, int row,
boolean hasFocus) {
String stringValue = tree.convertValueToText(value, sel,
expanded, leaf, row, hasFocus);
this.tree = tree;
this.hasFocus = hasFocus;
setText(stringValue);
Color fg = null;
isDropCell = false;
JTree.DropLocation dropLocation = tree.getDropLocation();
if (dropLocation != null
&& dropLocation.getChildIndex() == -1
&& tree.getRowForPath(dropLocation.getPath()) == row) {
Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
if (col != null) {
fg = col;
} else {
fg = getTextSelectionColor();
}
isDropCell = true;
} else if (sel) {
fg = getTextSelectionColor();
} else {
fg = getTextNonSelectionColor();
}
setForeground(fg);
Icon icon = null;
if (leaf) {
icon = getLeafIcon();
} else if (expanded) {
icon = getOpenIcon();
} else {
icon = getClosedIcon();
}
if (!tree.isEnabled()) {
setEnabled(false);
LookAndFeel laf = UIManager.getLookAndFeel();
Icon disabledIcon = laf.getDisabledIcon(tree, icon);
if (disabledIcon != null) icon = disabledIcon;
setDisabledIcon(icon);
} else {
setEnabled(true);
setIcon(icon);
}
setComponentOrientation(tree.getComponentOrientation());
selected = sel;
return this;
}