代码之家  ›  专栏  ›  技术社区  ›  John Doe

标签左对齐,按钮右对齐的组合

  •  0
  • John Doe  · 技术社区  · 6 年前

    我正在开发一个Eclipse插件,并在某个时刻显示一个弹出窗口。在弹出对话框中,我想创建一个区域,在该区域中,我在左侧有一个标签,在右侧有两个按钮。

    public void createBottom(Composite parent) {
        Composite composite = new Composite(parent, SWT.FILL | SWT.WRAP | SWT.BORDER);
        GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
        composite.setLayoutData(gridData);
        composite.setLayout(new GridLayout(3, false));
    
        addLabel(composite);
        addButton1(composite);
        addButton2(composite);
    }
    

    当前结果如下所示:
    this

    虽然我期待着这样的事情:
    enter image description here

    我如何可能对齐 Label 左边的按钮和右边的两个按钮?

    1 回复  |  直到 6 年前
        1
  •  2
  •   greg-449    6 年前

    第一 SWT.FILL SWT.WRAP 的有效样式 Composite . 控件的Javadoc指定可以使用哪些样式。

    使用类似以下内容:

    Composite composite = new Composite(parent, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    composite.setLayoutData(gridData);
    composite.setLayout(new GridLayout(3, false));
    
    Label label = new Label(composite, SWT.BEGINNING);
    label.setText("Test");
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    
    Button but1 = new Button(composite, SWT.PUSH);
    but1.setText("OK");
    but1.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    
    Button but2 = new Button(composite, SWT.PUSH);
    but2.setText("Close");
    but2.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    

    标签的布局数据将在组合中获取额外的空间,并且按钮具有端点对齐。