SWT工具栏问题
答
不幸的是,酷工具栏不具有对准场。然而,它确实有界限,可以用来将它对齐到右侧,并占据整个窗口的宽度。 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
我希望这有助于。