将树节点滚动到滚动窗格的顶部
I have a JTree
with about more than 8 tree nodes(leafs). The requirement is if user clicks on a tree node, the selected tree node will automatically scrolls to top of the scroll pane from any position. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如前所述:所有的scrollXXToVisible方法都会滚动,使得给定的XX在某处可见,它们不支持更精细的控制,因为fi“应该是可见区域中的第一个节点”。
您必须自己实现该功能,例如
“注意:这样做以响应节点上的鼠标事件可能会让用户感到烦恼,因为它会将目标从其脚下移动”。
As already noted: all scrollXXToVisible methods scroll such that the given XX is visible somewhere, they don't support finer control as f.i. "should be first node in visible area".
You have to implement that functionality yourself, something like
Beware: doing so in reaction to a mouse event on the node might be annoying to the user as it moves the target from under its feet.
在实际的
JTree
上使用scrollRectToVisible 方法。例子:
Use the scrollRectToVisible method on the actual
JTree
.Example:
这个问题很久以前就被问过,我不知道你是否还需要这个......
我理解你遇到的问题,问题是这样的:树选择侦听器不能按你的预期工作。您必须通过注册鼠标侦听器来检测单击事件。像这样:
干杯!
This question was asked a long time ago, and I don't know if you still need this...
I understand the problem you have, the issue is this: tree selection listeners don't work as you might expect. You have to detect the click event by registering a mouse listener. Something like this:
Cheers!