2012-09-17 46 views
0

我有一個讓SWT文本控件按照我希望它們在組內的方式出現問題。具體而言,我很難將傳遞到GridDataverticalSpan反映在GUI資產中。在下面的示例中,我無法正確顯示的3個控件是descriptionTextdefaultActionTextdefaultReportActionText,但translationText顯示屏正確顯示。我不確定我在這裏做錯了什麼,所以我很感激任何反饋!在一個組中排列SWT文本控件的困難

組:

paramsFieldComposite = new Group(upperRightComposite, SWT.BORDER); 
    // TODO: Change group to composite and remove .setText() 
    paramsFieldComposite.setText("paramsFieldComposite"); 
    paramsFieldComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 
    paramsFieldComposite.setLayout(new GridLayout(2, true)); 

翻譯控制(工作,我會爲1的寬度和高度3預計):

Label hostnameLabel = new Label(paramsFieldComposite, SWT.NONE); 
    hostnameLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); 
    hostnameLabel.setText(configResourceBundle.geti18nDisplay("HostnameLabel")); 

    Label translationLabel = new Label(paramsFieldComposite, SWT.NONE); 
    translationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); 
    translationLabel.setText(configResourceBundle.geti18nDisplay("TranslationLabel")); 

    hostnameText = new TextControl(paramsFieldComposite, SWT.BORDER); 
    hostnameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); 
    hostnameText.setEditable(true); 

    translationText = new TextControl(paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP); 
    translationText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3)); 
    translationText.setEditable(true); 

說明/動作控制(不工作爲我期待,我希望他們都有3而不是1的高度):

Label descriptionLabel = new Label(paramsFieldComposite, SWT.NONE); 
    descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
    descriptionLabel.setText(configResourceBundle.geti18nDisplay("DescriptionLabel")); 

    descriptionText = new TextControl(paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); 
    descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 3)); 
    descriptionText.setEditable(true); 

    Label defaultActionLabel = new Label(paramsFieldComposite, SWT.NONE); 
    defaultActionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); 
    defaultActionLabel.setText(configResourceBundle.geti18nDisplay("DefaultActionLabel")); 

    Label defaultReportActionLabel = new Label(paramsFieldComposite, SWT.NONE); 
    defaultReportActionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); 
    defaultReportActionLabel.setText(configResourceBundle.geti18nDisplay("DefaultReportActionLabel")); 

    defaultActionText = new TextControl(paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL); 
    defaultActionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3)); 
    defaultActionText.setEditable(true); 

    defaultReportActionText = new TextControl(paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL); 
    defaultReportActionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3)); 
    defaultReportActionText.setEditable(true); 

這是GUI的外觀喜歡。

enter image description here

回答

-1

translationTextdefaultActionText行爲之間的區別是很容易解釋。

你告訴兩個跨越3行。然而,雖然這三行translationText的高度由其他WidgetshostnameText,instanceLabel,instanceText)定義,但defaultActionText並非如此。這三行中沒有其他小部件(defaultReportActionText除外)。所以高度將被設置爲必要的高度。

您可以手動設置GridDataheightHint增加這個高度:

GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3); 
data.heightHint = 80; 

defaultActionText.setLayoutData(data); 
defaultReportActionText.setLayoutData(data); 

結果可以在這裏看到:

enter image description here

爲了得到更精確的結果的高度,您可以使用:

data.heightHint = hostnameText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y 
       + instanceLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y 
       + instanceText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; 
+0

謹慎解釋downvote? – Baz