Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the order of element in RowLayout SWT Java

Tags:

java

swt

Is there a way to change the order of the elements which are created in Row layout , I want to display it in the elements as first in first displayed. For example if I create element1 ,then element2 element3, element4

I want to see the layout as element4 element3 element2 element1

that mean the elements that last to be created will be the first element which will be displayed in the shell.

Is there easy way to work with the row layout and do it.

I want to change the following example to displayed Button99 Button98 Button97 Button96 Button95 Button94……………………………….

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TestExample
{
    public static void main(String[] args)
    {
        Display display = Display.getDefault();
        Shell shell = new Shell(display);
        RowLayout rowLayout = new RowLayout();

        shell.setLayout(rowLayout);

        for (int i=0;i<100;i++)
        {
            Button b1 = new Button(shell, SWT.PUSH);
            b1.setText("Button"+i);

        }
        shell.open();
        while (!display.isDisposed())
        {
            if (!display.readAndDispatch())
            {
                display.sleep();
            }
        }
    }
}

Thanks in Advance.

like image 732
user1205079 Avatar asked Feb 12 '12 17:02

user1205079


1 Answers

FillLayout, RowLayout and GridLayout use the z-order of the controls in order to determine the ordering of the controls. (Since those three layouts don't allow controls to visually overlap each other, the z-order would be otherwise ignored.)

The default z-order is based on creation - thus controls default to the order that you added them to their parent.

You can change the z-order (and thus, change the order that widgets are painted) using the Control.moveAbove() and Control.moveBelow() methods.

like image 131
Edward Thomson Avatar answered Oct 01 '22 10:10

Edward Thomson