gpt4 book ai didi

java - SWT工具栏问题

转载 作者:行者123 更新时间:2023-11-30 11:57:24 24 4
gpt4 key购买 nike

我有 2 个关于 SWT 的问题:

  1. 有没有一种快速的方法可以将工具栏对齐到窗口的右侧(在启动时)?

  2. 我可以创建一个占窗口 100% 的工具栏吗?

感谢您的帮助:)

最佳答案

不幸的是,CoolBar 没有对齐字段。但是它确实有边界,可用于将其对齐到右侧并使其占据窗口的整个宽度。 CoolBar 不允许高度超过 21,因此必须考虑窗口尺寸的高度以使其填满窗口。为此,计算必要的客户区大小,然后相应地调整 shell 的大小。 This thread可能有助于调整大小。

//This code will make the coolBar take up the entire window width running Windows 7 with default windows
Rectangle shellBounds = shell.getClientArea();
coolBar.setBounds(0, 0, shellBounds.width, shellBounds.height);

您可以使用相同的逻辑将 coolBar 调整到屏幕右侧。

//Justify the toolbar to the right side of the screen
int coolBarWidth = 200; //arbitrarily chosen dimensions
int coolBarHeight = 40;
coolBar.setBounds(shellBounds.width - coolBarWidth, 0, coolBarWidth, coolBarHeight);

此外,一些 coolBar 元素在其构造函数中具有对齐参数。

CLabel lblTest = new CLabel(coolBar, SWT.LEFT); //SWT.LEFT could be replaced with SWT.CENTER or SWT.RIGHT

希望对您有所帮助。

关于java - SWT工具栏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3845896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com