I am trying to created a scrolled composite that has a composite with a grid layout inside.
However when I try to set the content of the scrolled composite nothing loads. This appears only to affect composites with grid layouts.
What am I doing wrong?
My Code:
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));
After a bunch of fiddling I got the following to work hope it helps someone else out.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With