代码之家  ›  专栏  ›  技术社区  ›  Sebastian Dusza

SWT工具栏问题

  •  2
  • Sebastian Dusza  · 技术社区  · 14 年前

    关于SWT,我有两个问题:

    1. 是否有快速方法将工具栏与窗口右侧对齐(启动时)?

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

    感谢您的帮助:)

    1 回复  |  直到 13 年前
        1
  •  1
  •   Community    7 年前

    不幸的是,CoolBar没有对齐字段。但是,它确实有边界,可用于将其与右侧对齐,并使其占据窗口的整个宽度。CoolBar不允许高度超过21,因此必须考虑窗口尺寸的高度,以使其填充窗口。为此,请计算必要的工作区大小,然后相应地调整外壳的大小。 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
    

    我希望这有帮助。