簡體   English   中英

使用GridLayout時如何使滾動條在ScrolledComposite中工作?

[英]How to get the scrollbars to work in a ScrolledComposite when using GridLayout?

我正在嘗試使用具有固定大小內容的滾動復合內容,並在滾動復合內容的滾動復合顯示狀態信息下方添加一個標簽。 因為我希望控件與父控件一起調整大小,所以我在其父控件上使用了GridLayout。 但是我面臨着滾動復合滾動條和標簽控件位置的問題。 即,除非將scrolledcomposite的網格數據屬性設置為

grabExcessVerticalspace = true

如果我允許滾動復合材料抓住多余的垂直空間,則由於滾動復合材料之間的空間,標簽不會出現在滾動復合材料下方。

public class Snippet5 {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, true));

    // this button is always 400 x 400. Scrollbars appear if the window is
    // resized to be too small to show part of the button
    ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("fixed size button");
    b1.setSize(400, 400);
    c1.setAlwaysShowScrollBars(true);
    c1.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
    c1.setContent(b1);

    Label l = new Label(shell, SWT.BORDER);
    l.setText("button clicked");
    GridData layoutData = new GridData(SWT.LEFT, SWT.TOP, true, false);
    layoutData.heightHint = 30;
    layoutData.widthHint  = 400;
    l.setLayoutData(layoutData);

    shell.setSize(600, 300);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}

對於使標簽出現在滾動組合的正下方(修剪空間)並進行滾動工作的任何幫助,都將受到贊賞。

編輯:

預期行為:

  1. 標簽將占據額外的垂直空間。
  2. 當調整外殼大小時無法完全查看內容時,scrolledcomposite應該啟用垂直滾動。

在此處輸入圖片說明

您需要像這樣將ScrolledComposite的布局數據設置為FILL

new GridData( SWT.FILL, SWT.FILL, true, true );

這樣,ScrolledComposite將占用網格單元的可用空間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM