1

这应该很简单,但这是我第一次使用 SWT。这就是我到目前为止所拥有的。

public class TabsTest {

private Shell shell;
private CTabFolder folder;

public TabsTest(Display display){

    shell = new Shell(display);
    shell.setText("TabsTest");
    shell.setLayout(new FillLayout());

    CTabFolder folder = new CTabFolder(shell, SWT.CLOSE | SWT.BOTTOM);
    folder.setUnselectedCloseVisible(false);
    folder.setSimple(false);

    initUI(folder);

    shell.pack();
    shell.setBounds(500, 500, 400, 500);
    shell.open ();

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

public void initUI(CTabFolder folder){
    CTabItem NFL = new CTabItem(folder, SWT.NONE);
    NFL.setText("NFL Bets");

    Button okButton = new Button(folder, SWT.PUSH);
    okButton.setText("OK");
    okButton.setSize(10,10);

    NFL.setControl(okButton);

    CTabItem NBA = new CTabItem(folder,SWT.NONE);
    NBA.setText("NBA Bets");

    CTabItem CFB = new CTabItem(folder,SWT.NONE);
    CFB.setText("CFB Bets");        

    folder.setSize(800,500);

}

public static void main (String [] args) {
    Display display = new Display();
    new TabsTest(display);
    display.dispose();
}

}

这目前给我的是这个......

图片

我如何在右下角制作一个小按钮?或者只是一般将其变小并将其移动到某个地方。

4

1 回答 1

3

由于您使用的FillLayout是控件,因此该控件占用了整个可用空间。你需要的是一种不同的布局。我会建议你阅读这篇文章,这将是一个好的开始。

我通常更喜欢GridLayout它,因为它非常易于使用并且可以满足大多数需求。

已编辑:修改您的代码以使用GridLayout

public class TabsTest {

    private Shell shell;
    private CTabFolder folder;

    public TabsTest(Display display) {
        shell = new Shell(display);
        shell.setText("TabsTest");
        shell.setLayout(new GridLayout());

        CTabFolder folder = new CTabFolder(shell, SWT.CLOSE | SWT.BOTTOM);
        folder.setUnselectedCloseVisible(false);
        folder.setSimple(false);
        folder.setLayoutData(new GridData(GridData.FILL_BOTH));

        initUI(folder);

        shell.pack();
        shell.setBounds(500, 500, 400, 500);
        shell.open();

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

    public void initUI(CTabFolder folder) {
        CTabItem NFL = new CTabItem(folder, SWT.NONE);
        NFL.setText("NFL Bets");

        Composite nflParent = new Composite(folder, SWT.NONE);
        nflParent.setBackground(folder.getDisplay().getSystemColor(SWT.COLOR_BLUE));
        nflParent.setLayout(new GridLayout());

        Button okButton = new Button(nflParent, SWT.PUSH);
        okButton.setText("OK");

        GridData gd = new GridData();
        gd.verticalAlignment = GridData.END;
        gd.horizontalAlignment = GridData.END;
        gd.grabExcessHorizontalSpace = true;
        gd.grabExcessVerticalSpace = true;
        okButton.setLayoutData(gd);

        NFL.setControl(nflParent);

        CTabItem NBA = new CTabItem(folder, SWT.NONE);
        NBA.setText("NBA Bets");

        CTabItem CFB = new CTabItem(folder, SWT.NONE);
        CFB.setText("CFB Bets");

        folder.setSize(800, 500);
    }

    public static void main(String[] args) {
        Display display = new Display();
        new TabsTest(display);
        display.dispose();
    }
}
于 2012-12-21T23:47:43.193 回答