Reorder items in Java RowLayout SWT

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

I want to see the layout as element4 element3 element2 element1

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

Is there an easy way to work with a line layout and do it.

I want to change the following example to display Button99 Button98 Button97 Button96 Button95 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 at Advance.

+6
source share
3 answers

FillLayout , RowLayout and GridLayout use the z-order of the controls to determine the order of the controls , (Since these three layouts do not allow the controls to visually overlap, the z-order is otherwise ignored.)

By default, the z-order is based on creation - thus, the default order is the one you added to the parent.

You can change the z-order (and therefore change the order in which widgets are displayed) using the Control.moveAbove() and Control.moveBelow() methods.

+5
source

There seems to be no property to set so that the RowLayout elements are placed in the reverse order. Thus, you can hold the elements in the array in the reverse order, and then add them all in a loop or for this specific example, just change the start and end state of the for loop so that it is like Button99 Button98 ...: D

0
source

If you are using one of the swt layouts, then:

already: item01, item02, item03 insert item04 before item02: 1. create item04 2. item04.moveAbove (item02)

 Display display = new Display(); Shell shell = new Shell(display); shell.setSize(640, 480); shell.setLayout(new FillLayout()); final Composite itemComposite = new Composite(shell, SWT.NONE); itemComposite.setLayout(new RowLayout()); Label item01 = new Label(itemComposite, SWT.NONE); item01.setText("item01"); final Label item02 = new Label(itemComposite, SWT.NONE); item02.setText("item02"); Label item03 = new Label(itemComposite, SWT.NONE); item03.setText("item03"); Composite buttonComposite = new Composite(shell, SWT.NONE); buttonComposite.setLayout(new GridLayout()); Button insertItem = new Button(buttonComposite, SWT.NONE); insertItem.setText("Insert"); insertItem.addListener(SWT.Selection, new Listener() { public void handleEvent(Event arg0) { Label item04 = new Label(itemComposite, SWT.NONE); item04.setText("item04"); item04.moveAbove(item02); itemComposite.layout(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); 
0
source

Source: https://habr.com/ru/post/908271/


All Articles