本文整理了Java中javax.swing.JTree.getClosestRowForLocation()
方法的一些代码示例,展示了JTree.getClosestRowForLocation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.getClosestRowForLocation()
方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:getClosestRowForLocation
暂无
代码示例来源:origin: INRIA/spoon
@Override
public void mousePressed(MouseEvent e) {
getJTree().setSelectionRow(
getJTree().getClosestRowForLocation(e.getX(), e.getY()));
maybeShowPopup(e);
}
代码示例来源:origin: dsukhoroslov/bagri
public int getClosestRowForLocation(int x, int y) {
return tree.getClosestRowForLocation(x, y);
}
代码示例来源:origin: chatty/chatty
@Override
public void mousePressed(MouseEvent e) {
int row = tree.getClosestRowForLocation(e.getX(), e.getY());
if (row != -1) {
tree.setSelectionRow(row);
}
}
});
代码示例来源:origin: org.icepdf.os/icepdf-viewer
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
int row = commentTree.getClosestRowForLocation(e.getX(), e.getY());
commentTree.setSelectionRow(row);
contextMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
}
代码示例来源:origin: com.haulmont.thirdparty/swingx-core
@Override
protected void updateRolloverPoint(JComponent component, Point mousePoint) {
JTree tree = (JTree) component;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
int col = row < 0 ? -1 : 0;
rollover.x = col;
rollover.y = row;
}
代码示例来源:origin: org.swinglabs.swingx/swingx-core
@Override
protected void updateRolloverPoint(JComponent component, Point mousePoint) {
JTree tree = (JTree) component;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
int col = row < 0 ? -1 : 0;
rollover.x = col;
rollover.y = row;
}
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
@Override
protected void updateRolloverPoint(JComponent component, Point mousePoint) {
JTree tree = (JTree) component;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
int col = row < 0 ? -1 : 0;
rollover.x = col;
rollover.y = row;
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
@Override
protected void updateRolloverPoint(JComponent component, Point mousePoint) {
JTree tree = (JTree) component;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
int col = row < 0 ? -1 : 0;
rollover.x = col;
rollover.y = row;
}
代码示例来源:origin: org.netbeans.api/org-openide-explorer
@Override
protected void showPopup(MouseEvent e) {
int selRow = tree.getClosestRowForLocation(e.getX(), e.getY());
if (!tree.isRowSelected(selRow)) {
tree.setSelectionRow(selRow);
}
}
};
代码示例来源:origin: stackoverflow.com
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
public class JTreeTools {
public static List<TreeNode> getVisibleNodes(JScrollPane hostingScrollPane, JTree hostingJTree){
//Find the first and last visible row within the scroll pane.
final Rectangle visibleRectangle = hostingScrollPane.getViewport().getViewRect();
final int firstRow = hostingJTree.getClosestRowForLocation(visibleRectangle.x, visibleRectangle.y);
final int lastRow = hostingJTree.getClosestRowForLocation(visibleRectangle.x, visibleRectangle.y + visibleRectangle.height);
//Iterate through each visible row, identify the object at this row, and add it to a result list.
List<TreeNode> resultList = new ArrayList<TreeNode>();
for (int currentRow = firstRow; currentRow<=lastRow; currentRow++){
TreePath currentPath = hostingJTree.getPathForRow(currentRow);
Object lastPathObject = currentPath.getLastPathComponent();
if (lastPathObject instanceof TreeNode){
resultList.add((TreeNode)lastPathObject);
}
}
return(resultList);
}
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_components
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
int x = e.getX();
int y = e.getY();
JTree tree = (JTree) e.getSource();
int rowIndex = tree.getClosestRowForLocation(x, y);
if (rowIndex > -1) {
tree.setSelectionRow(rowIndex);
popupMenu.show(tree, x, y);
}
}
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
boolean selected = false;
// check the selected rows
int row = tree.getClosestRowForLocation(e.getPoint().x, e.getPoint().y);
TreePath[] paths = tree.getSelectionPaths();
// filter out all objects from the selection
if (paths != null) {
for (TreePath path : paths) {
if (path.getPathCount() > 1) {
if (tree.getRowForPath(path) == row) {
selected = true;
}
}
}
}
// if the row, which has been right clicked is not selected - select it
if (!selected) {
tree.getSelectionModel().setSelectionPath(tree.getPathForRow(row));
}
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
}
代码示例来源:origin: net.openhft/spoon-core
public void mousePressed(MouseEvent e) {
getJTree().setSelectionRow(
getJTree().getClosestRowForLocation(e.getX(), e.getY()));
maybeShowPopup(e);
}
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
@Override
public void mousePressed(MouseEvent e) {
JTree tree = (JTree) e.getComponent();
Point mousePoint = e.getPoint();
int labelRow = tree.getRowForLocation(mousePoint.x, mousePoint.y);
// default selection
if (labelRow >= 0)
return;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
// no hit
if (row < 0)
return;
tree.dispatchEvent(new MouseEvent(tree, e.getID(), e.getWhen(), e
.getModifiers(), bounds.x + bounds.width - 2, mousePoint.y, e
.getClickCount(), e.isPopupTrigger(), e.getButton()));
}
代码示例来源:origin: org.swinglabs.swingx/swingx-core
@Override
public void mousePressed(MouseEvent e) {
JTree tree = (JTree) e.getComponent();
Point mousePoint = e.getPoint();
int labelRow = tree.getRowForLocation(mousePoint.x, mousePoint.y);
// default selection
if (labelRow >= 0)
return;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
// no hit
if (row < 0)
return;
tree.dispatchEvent(new MouseEvent(tree, e.getID(), e.getWhen(), e
.getModifiers(), bounds.x + bounds.width - 2, mousePoint.y, e
.getClickCount(), e.isPopupTrigger(), e.getButton()));
}
代码示例来源:origin: com.haulmont.thirdparty/swingx-core
@Override
public void mousePressed(MouseEvent e) {
JTree tree = (JTree) e.getComponent();
Point mousePoint = e.getPoint();
int labelRow = tree.getRowForLocation(mousePoint.x, mousePoint.y);
// default selection
if (labelRow >= 0)
return;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
// no hit
if (row < 0)
return;
tree.dispatchEvent(new MouseEvent(tree, e.getID(), e.getWhen(), e
.getModifiers(), bounds.x + bounds.width - 2, mousePoint.y, e
.getClickCount(), e.isPopupTrigger(), e.getButton()));
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
@Override
public void mousePressed(MouseEvent e) {
JTree tree = (JTree) e.getComponent();
Point mousePoint = e.getPoint();
int labelRow = tree.getRowForLocation(mousePoint.x, mousePoint.y);
// default selection
if (labelRow >= 0)
return;
int row = tree.getClosestRowForLocation(mousePoint.x, mousePoint.y);
Rectangle bounds = tree.getRowBounds(row);
if (bounds == null) {
row = -1;
} else {
if ((bounds.y + bounds.height < mousePoint.y)
|| bounds.x > mousePoint.x) {
row = -1;
}
}
// no hit
if (row < 0)
return;
tree.dispatchEvent(new MouseEvent(tree, e.getID(), e.getWhen(), e
.getModifiers(), bounds.x + bounds.width - 2, mousePoint.y, e
.getClickCount(), e.isPopupTrigger(), e.getButton()));
}
代码示例来源:origin: jpcsp/jpcsp
private void showJTree (JScrollPane view, Point pt) {
JTree tree = (JTree) view.getViewport().getView();
Point p = SwingUtilities.convertPoint(view, pt.x, pt.y, tree);
int row = tree.getClosestRowForLocation(p.x, p.y);
TreePath path = tree.getClosestPathForLocation(p.x, p.y);
Rectangle bds = tree.getPathBounds(path);
if (bds == null || !bds.contains(p)) {
hide();
return;
}
if (setCompAndRow (tree, row)) {
Rectangle visible = getShowingRect (view);
Rectangle[] rects = getRects (bds, visible);
if (rects.length > 0) {
ensureOldPopupsHidden();
painter.configure(path.getLastPathComponent(),
view, tree, path, row);
showPopups (rects, bds, visible, tree, view);
} else {
hide();
}
}
}
代码示例来源:origin: org.netbeans.api/org-openide-explorer
pt.x, pt.y, tree);
int row = tree.getClosestRowForLocation(
p.x, p.y);
代码示例来源:origin: abbot/abbot
@Override
public JTreeLocation call() {
JTree tree = (JTree)c;
if (tree.getRowCount() == 0)
return new JTreeLocation(p);
Rectangle rect = tree.getRowBounds(tree.getRowCount()-1);
int maxY = rect.y + rect.height;
if (p.y > maxY)
return new JTreeLocation(p);
// TODO: ignore clicks to the left of the expansion control, or maybe
// embed them in the location.
TreePath path = tree.getClosestPathForLocation(p.x, p.y);
TreePath stringPath = pathToStringPath(tree, path);
if (stringPath != null) {
// if the root is hidden, drop it from the path
if (!tree.isRootVisible()) {
Object[] objs = stringPath.getPath();
Object[] subs = new Object[objs.length-1];
System.arraycopy(objs, 1, subs, 0, subs.length);
stringPath = new TreePath(subs);
}
return new JTreeLocation(stringPath);
}
int row = tree.getClosestRowForLocation(p.x, p.y);
if (row != -1) {
return new JTreeLocation(row);
}
return new JTreeLocation(p);
}
});
内容来源于网络,如有侵权,请联系作者删除!