本文整理汇总了Java中javax.swing.JTree.getRowForLocation方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.getRowForLocation方法的具体用法?Java JTree.getRowForLocation怎么用?Java JTree.getRowForLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.getRowForLocation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseClicked
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JTree tree = (JTree) e.getSource();
Point p = e.getPoint();
int row = tree.getRowForLocation(e.getX(), e.getY());
TreePath path = tree.getPathForRow(row);
// if path exists and mouse is clicked exactly once
if (path != null) {
FileNode node = (FileNode) path.getLastPathComponent();
Rectangle chRect = DeletedListRenderer.getCheckBoxRectangle();
Rectangle rowRect = tree.getPathBounds(path);
chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
if (e.getClickCount() == 1 && chRect.contains(p)) {
boolean isSelected = !(node.isSelected());
node.setSelected(isSelected);
((DefaultTreeModel) tree.getModel()).nodeChanged(node);
if (row == 0) {
tree.revalidate();
}
tree.repaint();
}
}
}
示例2: mousePressed
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent event) {
JTree tree = (JTree) event.getSource();
int x = event.getX();
int y = event.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
// if path exists and mouse is clicked exactly once
if (path == null) {
return;
}
CheckNode node = (CheckNode) path.getLastPathComponent();
if ( !SwingUtilities.isRightMouseButton(event)) {
return;
}
Object o = node.getUserObject();
}
示例3: mousePressed
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent event) {
JTree tree = (JTree) event.getSource();
int x = event.getX();
int y = event.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
// if path exists and mouse is clicked exactly once
if (path == null) {
return;
}
CheckNode node = (CheckNode) path.getLastPathComponent();
if ( !SwingUtilities.isRightMouseButton(event)) {
return;
}
Object o = node.getUserObject();
if ( !(o instanceof TreeElement)) {
return;
}
o = ((TreeElement) o).getUserObject();
if (o instanceof RefactoringElement) {
showPopup(((RefactoringElement) o).getLookup().lookupAll(Action.class), tree, x, y);
}
}
示例4: mouseClicked
import javax.swing.JTree; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent e) {
// todo (#pf): we need to solve problem between click and double
// click - click should be possible only on the check box area
// and double click should be bordered by title text.
// we need a test how to detect where the mouse pointer is
JTree tree = (JTree) e.getSource();
Point p = e.getPoint();
int x = e.getX();
int y = e.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
// if path exists and mouse is clicked exactly once
if( null == path )
return;
Node node = Visualizer.findNode( path.getLastPathComponent() );
if( null == node )
return;
Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
Rectangle rowRect = tree.getPathBounds(path);
chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
if (e.getClickCount() == 1 && chRect.contains(p)) {
boolean isSelected = settings.isNodeVisible( node );
settings.setNodeVisible( node, !isSelected );
tree.repaint();
}
}