将 SQLite 数据生成为按钮 (SWT)

Generate SQLite data as button (SWT)

我需要从 SQLite 数据生成按钮,但是像这张图片一样大小为 100%:

问题是我的主布局是绝对的:(

    TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
    //tabFolder.setLayout(new GridLayout());
    tabFolder.setBounds(10, 319, 740, 342);

    TabItem tbtmPizzas = new TabItem(tabFolder, SWT.NONE);
    tbtmPizzas.setText("Members");

    Composite composite = new Composite(tabFolder, SWT.NONE);
    tbtmPizzas.setControl(composite);


    // for this example, I simply repeated this button with different bounds
    Button button = new Button(composite, SWT.NONE);
    button.setText("Michael");
    button.setBounds(10, 10, 137, 52);

这应该可以帮助您开始工作:

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

    TabFolder folder = new TabFolder(shell, SWT.NONE);

    TabItem item = new TabItem(folder, SWT.NONE);
    item.setText("Item");

    Composite content = new Composite(folder, SWT.NONE);
    content.setLayout(new GridLayout(3, true));

    String[] myData = {"This", "is", "some", "random", "data"};

    for (String data : myData)
    {
        Button button = new Button(content, SWT.PUSH);
        button.setText(data);
        button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    }

    item.setControl(content);

    shell.pack();
    shell.open();

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

看起来像这样: