在 RowLayout SWT Java 中更改元素的顺序 [英] Change the order of element in RowLayout SWT Java

查看:29
本文介绍了在 RowLayout SWT Java 中更改元素的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法改变在 Row 布局中创建的元素的顺序,我想将它显示在元素中作为第一个显示的元素.例如,如果我创建 element1 ,然后 element2 element3, element4

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

我想将布局视为element4 element3 element2 element1

I want to see the layout as element4 element3 element2 element1

这意味着最后创建的元素将是第一个显示在 shell 中的元素.

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.

我想把下面的例子改成显示Button99 Button98 Button97 Button96 Button95 Button94……………………………….

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();
            }
        }
    }
}

提前致谢.

推荐答案

FillLayoutRowLayoutGridLayout 使用控件以确定控件的顺序.(由于这三种布局不允许控件在视觉上相互重叠,否则 z 顺序将被忽略.)

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.)

默认的 z-order 基于创建 - 因此控件默认为您将它们添加到其父级的顺序.

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

您可以使用 Control.moveAbove()Control.moveBelow() 方法更改 z 顺序(从而更改小部件的绘制顺序).

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

这篇关于在 RowLayout SWT Java 中更改元素的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆