layout - Can Java SWT GridLayout lay out widgets from right to left? -
from api document of gridlayout: "widgets laid out in columns left right,...", i'm wondering if there someway lay out widgets right left? or, when have 1 column applies gridlayout, can lay out widgets bottom top? (sorry poor english!)
the magic word here swt.right_to_left. however, not applied layout, composite containing widgets.
here example code:
public static void main(string[] args) { final display display = new display(); shell shell = new shell(display); shell.setlayout(new gridlayout(2, true)); shell.settext("expandbar example"); composite ltr = new composite(shell, swt.left_to_right); ltr.setlayout(new gridlayout(3, true)); ltr.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); composite rtl = new composite(shell, swt.right_to_left); rtl.setlayout(new gridlayout(3, true)); rtl.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); for(int = 0; < 10; i++) { new button(ltr, swt.push).settext("button " + i); new button(rtl, swt.push).settext("button " + i); } shell.pack(); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) { display.sleep(); } } display.dispose(); } and looks like:

to both right-to-left , bottom-to-top, you'll have use moveabove/movebelow null parameter:
public static void main(string[] args) { final display display = new display(); shell shell = new shell(display); shell.setlayout(new gridlayout(2, true)); shell.settext("stackoverflow"); composite ltr = new composite(shell, swt.left_to_right); ltr.setlayout(new gridlayout(3, true)); ltr.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); composite rtl = new composite(shell, swt.left_to_right); rtl.setlayout(new gridlayout(3, true)); rtl.setlayoutdata(new griddata(swt.fill, swt.fill, true, true)); int nrofitems = 10; int nrofcolumns = ((gridlayout) rtl.getlayout()).numcolumns; int filleritems = nrofcolumns - nrofitems % nrofcolumns; (int = 0; < nrofitems; i++) { new button(ltr, swt.push).settext("button " + i); new button(rtl, swt.push).settext("button " + i); } for(int = 0; < filleritems; i++) new label(rtl, swt.none); control[] children = rtl.getchildren(); (int = 0; < children.length; i++) { children[i].moveabove(null); } shell.pack(); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) { display.sleep(); } } display.dispose(); } looks this:

Comments
Post a Comment