将 2 个 jface TreeViewers 垂直对齐到特定元素
我在页面上有两个 TreeViewer
对象(2 列,每列中有一个 TreeViewer
),并且我想在滚动或选择另一个树时垂直对齐一棵树。
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Tree;
我认为解决方案应该类似于
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent arg0) {
TreeViewer mirrorTree = (treeViewer == treeVwrSource ? treeVwrTarget : treeVwrSource);
// find position of selected element (element x) in treeViewer
// set position of element x in mirrorTree, it is already selected.
}
});
“有什么建议吗?”
I have two TreeViewer
objects on a page (2 columns, one TreeViewer
in each column), and I want to vertically align a tree when the other is scrolled or selected.
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Tree;
I think the solution should look something like
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent arg0) {
TreeViewer mirrorTree = (treeViewer == treeVwrSource ? treeVwrTarget : treeVwrSource);
// find position of selected element (element x) in treeViewer
// set position of element x in mirrorTree, it is already selected.
}
});
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的阅读,滚动表或树是不可能直接实现的(除非同时发生变化)。以编程方式更改滚动条滑块的位置不会更改表/树的视口。
但是您可以尝试以下代码片段是否适合您:
您可以在注册到树的垂直滚动条 (
tree.getVerticalBar()
) 的SelectionListener
中调用该代码。同步选择相当容易(如果两个树查看器显示相同的输入/模型):(
由问题中的
ISelectionChangedListener
调用)。From what I've read, scrolling tables or trees isn't directly possible (unless that has changed in the meantime). Programmatically changing the position of the thumb of the scrollbar would not change the viewport of the table/tree.
But you could try if the following snippet works for you:
You would call that code in a
SelectionListener
registered to the vertical scrollbar of your tree (tree.getVerticalBar()
).Synchronizing the selection is fairly easy (if both tree viewers display the same input/model):
(called by the
ISelectionChangedListener
from your question).有关如何同步两个表的完整示例,请参阅此 SWT 代码段。
For a complete example of how to synchronize two tables see this SWT Snippet.