TableViewer填充时文本字段丢失

问题描述 投票:0回答:1

问题在Win10上发生。 Eclipse 4.13.0。

我在GridLayout的Text小部件上方有一个JFace TableViewer。每当我用内容填充表格时,“文本”小部件就会消失。如果我将Shell配置为FillLayout即可,但这不是我想要的,因为我有一些小部件不想占用任何空间(例如搜索字段,分隔符等)。

我似乎找不到问题,有什么建议吗?

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

public class TestDialog {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setBounds(10, 10, 800, 600);
        shell.setLayout(new GridLayout());

        Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
        separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        Link link = new Link(shell, SWT.NONE);
        link.setText("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore");
        link.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));

        Text txtSearch = new Text(shell, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
        txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        txtSearch.setMessage("Enter search phrase here");

        TableViewer tableViewer = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
        tableViewer.setContentProvider(ArrayContentProvider.getInstance());

        Table table = tableViewer.getTable();
        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

        Group grp = new Group(shell, SWT.NONE);
        grp.setText("MyGroup:");
        grp.setLayout(new FillLayout(SWT.HORIZONTAL));
        grp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

        Text txt = new Text(grp, SWT.WRAP);

        List<String> entries = new ArrayList<String>();
        for (int i = 0; i < 100; i++) {
            entries.add("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore");
        }

        tableViewer.setInput(entries);      

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}
swt jface
1个回答
0
投票

表格正在展开以显示所有行,这将表格下方的所有内容从窗口中推出。

您需要为表格指定高度提示:

Table table = tableViewer.getTable();
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
data.heightHint = 200;
table.setLayoutData(data);
© www.soinside.com 2019 - 2024. All rights reserved.