Java SWT 在屏幕上集中绝对合成

Java SWT Centralize absolute composite on screen

我正在开发一个应用程序,我的雇主要求它应该有一个绝对大小 (1024 x 768)。是否可以将此绝对合成插入另一个具有填充布局(或任何其他布局)的合成并将绝对布局设置为始终集中?

我是开发屏幕的新手,所以我对这个概念很困惑。

提前致谢。

您可以使用 GridLayout 将 Composite 置于 Shell 的中心。

类似于:

Display display = new Display();

Shell shell = new Shell(display, SWT.SHELL_TRIM);

shell.setText("Stack Overflow");

shell.setFullScreen(true);

shell.setLayout(new GridLayout());

// Composite, just using a border here to show where it is
Composite composite = new Composite(shell, SWT.BORDER);

// Center composite in the shell using all available space 
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));

composite.setLayout(new GridLayout());

// Something to put in the composite
Label label = new Label(composite, SWT.BEGINNING);
label.setText("Text");

shell.open();

while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
      display.sleep();
  }

display.dispose();