使用 SWT.NO_BACKGROUND 重绘复合后面的控件
最初目标:
我有一个 TreeMenu,用来显示我的菜单。 在此树中,用户可以选择不同的项目。
我想禁用该树,以便用户在选择第一个项目后无法选择新项目。 问题是,我们不能使用 setEnabled,因为我们不允许使用灰色外观。外观/颜色可能不会改变。
我们提出的解决方案
我们的第一个想法是在菜单顶部使用带有 SWT.NO_BACKGROUND 的 Composite,以防止用户与 TreeMenu 进行任何交互。
代码:
final Composite cover = new Composite(getPage().shell, SWT.NO_BACKGROUND);
cover.setLocation(getMenu().getLocation());
cover.setSize(getMenu().getSize());
cover.moveAbove(getMenu());
这有重画的问题。
如果屏幕被另一个屏幕覆盖然后回到前面,则覆盖复合材料将填充前一个重叠窗口的片段。
我们的想法是手动重绘菜单:
cover.moveBelow(getMenu());
getMenu().update();
cover.moveAbove(getMenu());
我们将代码放置在paintEventListener 中。
但这造成了死循环,并没有解决问题。
问题
有人知道我们如何实现最初的目标吗?
有谁知道我们如何使我们提出的解决方案发挥作用?
Original goal:
I have a TreeMenu that i use to display my Menu.
In this tree, a user can select different items.
I would like to disable the tree, so that a user cannot select a new item after choosing the first.
The catch is, we cannot use setEnabled, because we are not allowed to use the greyed out look. The look/colors may not change.
Our proposed solution
Our first idea was to use a Composite with SWT.NO_BACKGROUND on top of the menu, to prevent any user interaction with the TreeMenu.
Code:
final Composite cover = new Composite(getPage().shell, SWT.NO_BACKGROUND);
cover.setLocation(getMenu().getLocation());
cover.setSize(getMenu().getSize());
cover.moveAbove(getMenu());
This has a problem with redrawing.
If the screen is covered by another screen and then brought back to front, the Cover Composite is filled with fragments of the previous overlapping window.
Our idea was to manually redraw the menu:
cover.moveBelow(getMenu());
getMenu().update();
cover.moveAbove(getMenu());
We placed the code inside the paintEventListener.
But this caused an infinite loop and did not solve the problem.
Questions
Does anyone have an idea how we can achive our orignial goal?
Does anyone know how we can make our proposed solution work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 SWT-Snippet80。它展示了如何防止选择。解决您的问题的方法是将这样的侦听器添加到您的树中:
我不建议尝试实施您的解决方法。我相信在 SWT 中不支持将透明控件放在彼此之上 - 我想我曾经读过 Steve Northover 关于这个主题的评论。即使你让它在某些操作系统上工作,它也可能无法在另一个操作系统上工作——这太像黑客了。
SWT 支持的解决方案是在彼此之上设置透明窗口。但这也很难实现(调整大小、移动、始终位于顶部、重绘工件),并且可能与其他解决方法一样大。去找听者。
Look at SWT-Snippet80. It shows how to prevent selections. A solution to your problem would be adding a listener like this to your tree:
I wouldn't recommend trying to implement your workaround. I believe that placing transparent controls on top of each other is unsupported in SWT - I think I read a comment from Steve Northover on this subject once. Even if you made it work for some OS, it probably won't work in another - it's too much of a hack.
A solution that is supported by SWT, is having transparent windows on top of each other. But that is also really hard to implement (resizing, moving, always on top, redraw artifacts) and probably as big a hack as the other workaround. Go for the listener.