SWT检查外壳是否超过屏幕边界

发布于 2025-01-25 10:01:31 字数 329 浏览 2 评论 0原文

我有一个按钮在我的应用程序中打开外壳,该按钮显示了许多复选框,以及底部的2个按钮。问题在于,由于高度太大,它可能会被切断。

我想要的解决方案是将外壳的内容添加到滚动式复合材料中,这是行不通的,因为外壳只是高度扩展,因此复合式的滚动条无需做任何事情。

我认为最好的方法是计算外壳是否超过屏幕界限,但我不明白其坐标如何真正起作用。 Shell的父是外壳,因此shell :: getBounds()应该返回坐标相对于显示相对于Monitor (在这种情况下,我可以通过shell :: getMonitor())获得。

我该怎么做?

I have a button that opens a shell in my application, which displays a number of checkboxes, along with 2 buttons at the bottom. The problem is that it can get cut off due to its height being too big.

The solution I want is to add the contents of the shell to a ScrollableComposite, which doesn't work, because the shell just expands in height, so the composite's scrollbars don't do anything.

I figured the best way would be to calculate if the shell exceeds the screen bounds, but I don't understand how its coordinates really work. The shell's parent is a shell, so Shell::getBounds() is supposed to return the coordinates relative to the display, but I think I need the shell's bounds relative to the monitor (which I can get through Shell::getMonitor()) in this case.

How can I do this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南冥有猫 2025-02-01 10:01:31

只需根据监视器的大小而不是边界设置外壳尺寸即可。

这是Eclipse启动配置对话框用来确保其不太大的内容:

protected void setShellSize(int width, int height) {
    Rectangle bounds = getShell().getMonitor().getBounds();
    getShell().setSize(Math.min(width, bounds.width), Math.min(height, bounds.height));
}

Just set the shell size based on the monitor size rather than the bounds.

This is what the Eclipse Launch Configuration Dialog uses to make sure it is not too big:

protected void setShellSize(int width, int height) {
    Rectangle bounds = getShell().getMonitor().getBounds();
    getShell().setSize(Math.min(width, bounds.width), Math.min(height, bounds.height));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文