2016-07-06 53 views

回答

2

當然這是可能的:

public static void main(String[] args) { 
    final Display display = new Display(); 
    final Shell shell = new Shell(display); 
    shell.setText("Stackoverflow"); 
    shell.setLayout(new FillLayout()); 

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL); 

    Button button = new Button(sc, SWT.NONE); 
    button.setText("Hello! This is a button with a lot of text..."); 

    sc.setContent(button); 
    sc.setExpandHorizontal(true); 
    sc.setExpandVertical(true); 
    sc.setMinSize(button.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 

    shell.pack(); 
    shell.open(); 

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

之前調整:

enter image description here

調整後:

enter image description here

只記得打電話ScrolledComposite#setContent(Control)Button作爲參數。

+0

是。我忘了#setcontent。謝謝。 – Rajasekhar

相關問題