2012-04-26 14 views
5

İçinde ızgara düzeni olan bir bileşene sahip kaydırılmış bir bileşik oluşturmaya çalışıyorum.Kaydırılmış Kompozit İçinde GridLayout Kullan

Ancak, kaydırılan kompozitin içeriğini ayarlamaya çalıştığımda hiçbir şey yüklenmiyor. Bu, yalnızca ızgara düzenleri olan kompozitleri etkilemek için görünür.

Neyi yanlış yapıyorum?

Benim Kod:

CTabItem tbtmNotes = new CTabItem(tabFolder, SWT.NONE); 
    tbtmNotes.setText("Notes"); 
    ScrolledComposite scrollComposite = new ScrolledComposite(tabFolder, SWT.V_SCROLL | SWT.BORDER); 
    tbtmNotes.setControl(scrollComposite); 
    scrollComposite.setContent(new hm_Composites.Comp_Animal_Notes(tabFolder, SWT.None, a)); 

cevap

9

işe yaramaz bir demet sonra ben umut çalışmak için aşağıdaki başkası yardımcı oluyor aldık.

public Comp_Animal_Notes(Composite parent, int style, Animal a) 
     throws Exception { 
    super(parent, SWT.NONE); 
    setLayout(new FillLayout(SWT.HORIZONTAL)); 
    ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 
    scrolledComposite.setExpandHorizontal(true); 
    scrolledComposite.setExpandVertical(true); 

    Composite composite = new Composite(scrolledComposite, SWT.NONE); 
    composite.setLayout(new GridLayout(2, false)); 

    ArrayList<Note> alNotes = a.getAnimalNotes(); 
    this.setRedraw(false); 
    for (int i = 0; i < alNotes.size(); i++) { 
     Note note = alNotes.get(i); 

     CLabel lblNoteDate = new CLabel(composite, SWT.BORDER); 
     lblNoteDate.setFont(SWTResourceManager.getFont("Tahoma", 8, 
       SWT.BOLD)); 
     lblNoteDate.setText("Date:"); 
     lblNoteDate.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 

     CLabel lblNotedatetxt = new CLabel(composite, SWT.BORDER); 
     lblNotedatetxt.setBackground(SWTResourceManager 
       .getColor(SWT.COLOR_WHITE)); 
     lblNotedatetxt.setText(note.getUserDate()); 
     lblNotedatetxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 

     CLabel lblNoteTxt = new CLabel(composite, SWT.BORDER); 
     lblNoteTxt.setBackground(SWTResourceManager 
       .getColor(SWT.COLOR_WHITE)); 
     lblNoteTxt.setText(note.getStrNote()); 
     lblNoteTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 
    } 

    scrolledComposite.setContent(composite); 
    scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 

    this.setRedraw(true); 
} 
+0

Gerçekten çok yardımcı! Paylaşım için teşekkürler! –

4

Talon06'dan snippet çalışmıyorsa, aşağıdaki değişiklikleri yapmayı deneyin.

scrolledComposite.setContent(composite); 

//add this line 
composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 

//not sure about this line, was optional in my case 
scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 

this.setRedraw(true); 

Ben açıkça kompozit boyutunu ayarlamak eğer ScrolledComposite içinde bileşenler sadece görünür elde alındığını tespit eder.

@ Talon06: Harika bulmanız için teşekkürler!

+0

Değişiklikler için teşekkürler, bu, kompozitin Windows Builder Tasarım sekmesinde görünür olmasını sağladığından işleri daha hızlı hale getiriyor. – Talon06