2013-09-26 62 views
0

我有兩個標籤放置在gridLayout中。標籤1只是一個單詞,標籤2是4行。 由於標籤2是4行,因此標籤1是垂直居中的,但我希望垂直位於頂部。將標籤放置在頂部SWT

下面是我用過的標籤設置。

Label label = new Label(parent, SWT.WRAP); 
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, false, false); 
    gd.widthHint = 200; 
label.setLayoutData(gd); 

請幫我把頂部的標籤對準不在中心的標籤1

回答

1

如果你看看GridData.HORIZONTAL_ALIGN_BEGINNINGGridData.VERTICAL_ALIGN_BEGINNING的Javadoc,你可以看到,它說:

不推薦。改爲使用新的GridData(SWT.BEGINNING,int,boolean,boolean)。

不推薦。改爲使用新的GridData(int,SWT.BEGINNING,boolean,boolean)。

始終使用SWT校準常數:

public static void main(String[] args) 
{ 
    Display display = Display.getDefault(); 
    final Shell shell = new Shell(display); 
    shell.setText("StackOverflow"); 
    shell.setLayout(new GridLayout(2, false)); 

    Label left = new Label(shell, SWT.BORDER); 
    left.setText("LEFT"); 
    Label right = new Label(shell, SWT.BORDER); 
    right.setText("RIGHT\nRIGHT\nRIGHT\nRIGHT"); 

    GridData data = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); 
    left.setLayoutData(data); 
    data = new GridData(SWT.FILL, SWT.FILL, true, true); 
    right.setLayoutData(data); 

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

是這樣的:

enter image description here

相關問題