java - ScrolledComposite wont display in TabFolder -
i having difficult time trying find example scrollbars work expected inside tabfolder. below sample code. can show me doing wrong, or if bug?
import org.eclipse.swt.swt; import org.eclipse.swt.custom.scrolledcomposite; import org.eclipse.swt.layout.griddata; import org.eclipse.swt.layout.gridlayout; import org.eclipse.swt.widgets.composite; import org.eclipse.swt.widgets.display; import org.eclipse.swt.widgets.shell; import org.eclipse.swt.widgets.tabfolder; import org.eclipse.swt.widgets.tabitem; import org.eclipse.swt.widgets.text; public class test { public static void main(string[] args) { display display = new display(); shell shell = new shell(display, swt.shell_trim); shell.setlayout(new gridlayout(1, false)); tabfolder tabfolder = new tabfolder(shell, swt.null); tabitem tab = new tabitem(tabfolder, swt.null); scrolledcomposite scrolledcomposite = new scrolledcomposite(tabfolder, swt.h_scroll | swt.v_scroll); scrolledcomposite.setexpandhorizontal(true); scrolledcomposite.setexpandvertical(true); scrolledcomposite.setlayout(new gridlayout(1, false)); scrolledcomposite.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); composite innercomposite = new composite(scrolledcomposite, swt.null); (int x = 0; x < 20; x++) { text t = new text(innercomposite, swt.border); t.settext(x + ""); } innercomposite.setlayout(new gridlayout(2, false)); innercomposite.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); scrolledcomposite.setcontent(innercomposite); scrolledcomposite.setminsize(scrolledcomposite.computesize(swt.default, swt.default)); tab.setcontrol(scrolledcomposite); shell.setsize(100, 100); shell.open(); while (!shell.isdisposed()) { if (!shell.getdisplay().readanddispatch()) { shell.getdisplay().sleep(); } } display.dispose(); } }
there number of issues in this. see comments in code:
tabfolder tabfolder = new tabfolder(shell, swt.null); // must set layout data shell gridlayout tabfolder.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); tabitem tab = new tabitem(tabfolder, swt.null); scrolledcomposite scrolledcomposite = new scrolledcomposite(tabfolder, swt.h_scroll | swt.v_scroll); scrolledcomposite.setexpandhorizontal(true); scrolledcomposite.setexpandvertical(true); // scrolledcomposite ignores setlayout // scrolledcomposite.setlayout(new gridlayout(1, false)); // tabfolder doesn't use griddata // scrolledcomposite.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); composite innercomposite = new composite(scrolledcomposite, swt.null); (int x = 0; x < 20; x++) { final text t = new text(innercomposite, swt.border); t.settext(x + ""); } innercomposite.setlayout(new gridlayout(2, false)); innercomposite.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); scrolledcomposite.setcontent(innercomposite); // minsize should computed size of inner composite scrolledcomposite.setminsize(innercomposite.computesize(swt.default, swt.default)); tab.setcontrol(scrolledcomposite);
Comments
Post a Comment