SWT RowLayout最后一个元素是否占据了多余的水平空间? [英] SWT RowLayout with last element grabbing excess horizontal space?

查看:146
本文介绍了SWT RowLayout最后一个元素是否占据了多余的水平空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在水平 RowLayout 中有两个元素。
我能够为第二个元素(例如200 px)指定(最小)。此外...

I have two elements in a horizontal RowLayout. I am able to specify a (minimal) with for the second element (e.g. 200 px). Furthermore...

a)如果shell的总宽度太小,则第二个元素换行到新行。使用 RowLayout 可以正常工作。

a) If the total width of the shell is too small, the second element wraps to a new line. That works fine with the RowLayout.

b)如果总和为大,则第二个(=最后一个)元素应抓住多余的水平空间

b) If the total with is "large", the second (=last) element should grab the excess horizontal space.

b)是否可以使用 RowLayout ?或者我是否需要使用 GridLayout 并自行实现包装(例如,在网格布局中使用一列或两列,具体取决于元素的大小)? / p>

Is b) possible with the RowLayout? Or do I need to use a GridLayout and implement the wrapping on my own (e.g. use one or two columns in the grid layout, depending on the size of the elements)?

public class RowLayoutDemo {

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

        Text firstElement = new Text(shell, SWT.NONE);
        firstElement.setText("firstElement");

        Text secondElement = new Text(shell, SWT.NONE);
        secondElement.setText("secondElement");
        secondElement.setBackground(new Color(null, 200, 0, 0));

        int minWidth = 200;
        RowData rowData = new RowData();
        rowData.width = minWidth;
        secondElement.setLayoutData(rowData);

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

< a href =https://i.stack.imgur.com/QlRoV.png =nofollow noreferrer>

推荐答案

RowLayout 不支持你要找的东西。我建议使用 GridLayout 和你建议的调整大小监听器,或者实现你自己的布局。

The RowLayout does not support what you are looking for. I recommend using a GridLayout with a resize listener as you suggested or implement your own layout.

这篇关于SWT RowLayout最后一个元素是否占据了多余的水平空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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