【问题标题】:SWT java - painting with GridData and GridLayoutSWT java - 使用 GridData 和 GridLayout 进行绘画
【发布时间】:2014-05-24 18:14:34
【问题描述】:

我正在尝试绘制一个外壳(实际上是一个带有复合材料的选项卡),它看起来像我附加的图像中的样子。 我为每个小部件尝试了几乎所有东西 - GridData,GridLayout,试图改变水平跨度和列数,但没有出现我需要的...... :(

我尝试使用此链接http://www.eclipse.org/articles/Article-Understanding-Layouts/Understanding-Layouts.htm 但没有成功。

有人可以指导我吗?

谢谢

【问题讨论】:

    标签: java eclipse swt


    【解决方案1】:

    这对你来说应该是一个很好的起点:

    public static void main(String args[])
    {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setText("StackOverflow");
        shell.setLayout(new GridLayout(2, false));
    
        Composite radioLeft = new Composite(shell, SWT.BORDER);
        radioLeft.setLayout(new GridLayout(6, false));
        radioLeft.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
        for (int i = 0; i < 12; i++)
        {
            Button button = new Button(radioLeft, SWT.RADIO);
            button.setText("Radio " + i);
            button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        }
    
        Composite radioRight = new Composite(shell, SWT.BORDER);
        radioRight.setLayout(new GridLayout(4, false));
        radioRight.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
        for (int i = 0; i < 8; i++)
        {
            Button button = new Button(radioRight, SWT.RADIO);
            button.setText("Radio " + i);
            button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        }
    
        Group groupLeft = new Group(shell, SWT.NONE);
        groupLeft.setLayout(new GridLayout(6, false));
        groupLeft.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
        for (int i = 0; i < 12; i++)
        {
            Label label = new Label(groupLeft, SWT.NONE);
            label.setText("Something " + i);
            label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        }
    
        Group groupRight = new Group(shell, SWT.NONE);
        groupRight.setLayout(new GridLayout(1, false));
        groupRight.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    
        for (int i = 0; i < 2; i++)
        {
            Label label = new Label(groupRight, SWT.NONE);
            label.setText("Something " + i);
            label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        }
        Group bottom = new Group(shell, SWT.NONE);
        bottom.setLayout(new GridLayout(6, false));
        bottom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
        for (int i = 0; i < 12; i++)
        {
            Label label = new Label(bottom, SWT.NONE);
            label.setText("Something " + i);
            label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        }
    
        Composite buttonComp = new Composite(shell, SWT.NONE);
        buttonComp.setLayout(new GridLayout(2, true));
        buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
        Button left = new Button(buttonComp, SWT.PUSH);
        left.setText("Left");
        left.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        Button right = new Button(buttonComp, SWT.PUSH);
        right.setText("Right");
        right.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
        shell.pack();
        shell.open();
    
        while (!shell.isDisposed())
        {
            if (!shell.getDisplay().readAndDispatch())
                shell.getDisplay().sleep();
        }
    }
    

    看起来像这样:

    【讨论】:

      猜你喜欢
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 2016-06-07
      • 1970-01-01
      相关资源
      最近更新 更多