2017-06-29 31 views
0

我正在開發一個帶有視圖的eclipse插件,我需要使這個視圖可以滾動。我發現如何讓它滾動,但複合出現在視圖的右側。如何填寫所有視圖?SWT Composite出現在右邊

我的代碼:

public class Comp2 extends Composite { 

    public Comp2(Composite parent, int style) { 
     super(parent, SWT.NONE); 

     final ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); 
     sc.setLayout(new FillLayout()); 
     sc.setExpandHorizontal(true); 
     sc.setExpandVertical(true); 

     final Composite subContainer = new Composite(sc, SWT.NONE); 

     Button btnNewButton = new Button(subContainer, SWT.NONE); 
     btnNewButton.setBounds(75, 99, 90, 30); 
     btnNewButton.setText("New Button"); 

     Button btnNewButton_1 = new Button(subContainer, SWT.NONE); 
     btnNewButton_1.setBounds(357, 398, 90, 30); 
     btnNewButton_1.setText("New Button"); 

     sc.setContent(subContainer); 

     sc.addControlListener(new ControlAdapter() { 

      @Override 
      public void controlResized(ControlEvent e) { 
       Rectangle r = sc.getClientArea(); 
       sc.setMinSize(subContainer 
         .computeSize(r.width, SWT.DEFAULT)); 
      } 
     }); 
    } 

    @Override 
    protected void checkSubclass() { 
     // Disable the check that prevents subclassing of SWT components 
    } 
} 

my view

回答

1

既然要擴展Composite複合是增加其正常的身體父。然後,您將ScrolledComposite添加到父級,因此它與第一個複合材料並排放置。

你可以通過改變它的父把CompositeScrollComposite

super(parent, SWT.NONE); 

// This composite needs a layout 
setLayout(new FillLayout()); 

// Parent of the ScrolledComposite is this Composite 
ScrolledComposite sc = new ScrolledComposite(this, SWT.H_SCROLL | SWT.V_SCROLL); 
+0

感謝的!現在可以了! –

相關問題