The magic word here is SWT.RIGHT_TO_LEFT
. However, it is not applied to the Layout
, but to the Composite
containing your widgets.
Here is some 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 i = 0; i < 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 this is what it looks like:
To get both right-to-left and bottom-to-top, you'll just have to use moveAbove
/moveBelow
with null
as the 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;
for (int i = 0; i < nrOfItems; i++)
{
new Button(ltr, SWT.PUSH).setText("Button " + i);
new Button(rtl, SWT.PUSH).setText("Button " + i);
}
for(int i = 0; i < fillerItems; i++)
new Label(rtl, SWT.NONE);
Control[] children = rtl.getChildren();
for (int i = 0; i < children.length; i++)
{
children[i].moveAbove(null);
}
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
Looks like this: