2017-02-18 53 views
0

我正在開發一個應用程序,我的僱主要求它應該有一個絕對大小(1024 x 768)。是否可以將這個絕對合成插入到具有填充佈局(或任何其他)的另一個合成中,並將絕對佈局設置爲始終集中?Java SWT在屏幕上集中絕對合成

我對開發屏幕相當新穎,所以我很困惑這個概念。

在此先感謝。

+1

我不清楚你在問什麼。設置Shell的大小和位置很簡單,這是不是你想要的? –

+0

@ gre-449抱歉,如果不清楚。 –

+0

我想要做的是:我想有一個大小設置爲填充屏幕的外殼。在這個shell裏面,我想要一個複合(1024x768)總是設置在屏幕的中心。訪問它的計算機的分辨率無關緊要。 –

回答

1

您可以使用GridLayout來將殼體中的複合材料居中。

喜歡的東西:

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(); 
+0

謝謝,Greg。這正是我所需要的。 –