Java 为什么表查看器';向导页面在展开后恢复正常大小后,水平滚动是否消失?

Java 为什么表查看器';向导页面在展开后恢复正常大小后,水平滚动是否消失?,java,eclipse-plugin,swt,jface,wizard,Java,Eclipse Plugin,Swt,Jface,Wizard,我在向导页面上显示了一个表查看器。第一次显示页面时,如下图所示,水平和垂直滚动条以黄色突出显示- 向导页面在两个方向上展开后,水平滚动条将消失,然后恢复到正常大小。如下图所示,只有垂直滚动条存在,但水平滚动条丢失 如何恢复水平滚动条 模拟上述示例的代码片段如下所示- package somepkg; import java.util.HashSet; import java.util.Set; import org.eclipse.jface.layout.TableColumnLayo

我在向导页面上显示了一个表查看器。第一次显示页面时,如下图所示,
水平
垂直
滚动条以黄色突出显示-

向导页面在两个方向上展开后,水平滚动条将消失,然后恢复到正常大小。如下图所示,只有垂直滚动条存在,但水平滚动条丢失

如何恢复水平滚动条

模拟上述示例的代码片段如下所示-

package somepkg;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;


public class MakeNodesSuccessWizardPage extends WizardPage {

    private Composite top;
    private TableViewer viewer;
    private TableColumnLayout tableLayout;

    public MakeNodesSuccessWizardPage() {
        super("MyPage");
        setTitle("Some Title");
        setMessage("Some Message");
    }

    @Override
    public void createControl(Composite parent) {
        top = new Composite(parent, SWT.NONE);
        top.setLayout(new GridLayout());
        setControl(top);
        createViewer(top);
        createHelp();
        setPageComplete(false);
    }

    private void createHelp() {
        Composite wrapper = new Composite(top, SWT.NONE);
        wrapper.setLayout(new GridLayout(2, false));
        wrapper.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        createFirstRow(wrapper);
        createSecondRow(wrapper);
        createThirdRow(wrapper);

    }

    private void createFirstRow(Composite wrapper) {
        //column 1 
        Label greenMark = new Label(wrapper, SWT.NONE);
        greenMark.setText("Cheched ");

        //column 2 
        Label help = new Label(wrapper, SWT.NONE);
        help.setText("indicates that a node is newly created");
    }

    private void createSecondRow(Composite wrapper) {
        //column 1 
        Label crossMark = new Label(wrapper, SWT.NONE);
        crossMark.setText("Unchecked ");

        //column 2 
        Label help = new Label(wrapper, SWT.NONE);
        help.setText("indicates that a node is an existing one, and so left untouched");
    }

    private void createThirdRow(Composite wrapper) {
        //column 1 
        Label refresh = new Label(wrapper, SWT.NONE);
        refresh.setText("Refresh");

        Label help = new Label(wrapper, SWT.NONE);
        help.setText("The Selected Server Node in the Package Navigator will Auto Refresh if there is/are any node(s) created");
    }

    private void createViewer(Composite parent) {

        tableLayout = new TableColumnLayout();

        // A separate composite containing just the table viewer is required
        Composite tableComp = new Composite(parent, SWT.NONE);

        tableComp.setLayout(tableLayout);
        tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        viewer = new TableViewer(tableComp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        createColumns(parent, viewer);
        final Table table = viewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        viewer.setContentProvider(new ArrayContentProvider());

        // Layout the viewer
        GridData gridData = new GridData();
        gridData.verticalAlignment = GridData.FILL;
        gridData.horizontalSpan = 2;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalAlignment = GridData.FILL;
        viewer.getControl().setLayoutData(gridData);
    }

    public TableViewer getViewer() {
        return viewer;
    }

    // This will create the columns for the table
    private void createColumns(final Composite parent, final TableViewer viewer) {
        TableViewerColumn col = createTableViewerColumn("Name", 100, 0);
        col.setLabelProvider(new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
                return (String)element;
            }
        });
        tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(100));

    }

    private TableViewerColumn createTableViewerColumn(String title, int bound, final int colNumber) {
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.LEAD);
        final TableColumn column = viewerColumn.getColumn();
        column.setText(title);
        column.setWidth(bound);
        column.setResizable(true);
        column.setMoveable(true);
        column.setAlignment(SWT.CENTER);
        return viewerColumn;

    }

    @Override
    public void setVisible(boolean visible) {
        if (visible) {
            Set<String> components = new HashSet<>();
            components.add("In the midst of chaos, there is also opportunity");
            components.add("Remote work is/will be the new TREND");
            components.add("All these years, all these memories, there was you. You pull me through time.");
            components.add("I will not die, not here, not now, never...");
            components.add("Death is the road to awe.");
            components.add("There's been progress at work.");
            components.add("Death is a disease, it's like any other. And there's a cure. A cure - and I will find it.");
            components.add("Our bodies are prisons for our souls. Our skin and blood, the iron bars of confinement. ");
            components.add("But fear not. All flesh decays. Death turns all to ash. And thus, death frees every soul.");
            components.add("our destiny is life!");
            components.add("I'm not afraid anymore, Tommy");

            viewer.setInput(components);
            top.layout();
            setPageComplete(false);
        }
        super.setVisible(visible);
    }
}
package-somepkg;
导入java.util.HashSet;
导入java.util.Set;
导入org.eclipse.jface.layout.TableColumnLayout;
导入org.eclipse.jface.viewers.ArrayContentProvider;
导入org.eclipse.jface.viewers.ColumnLabelProvider;
导入org.eclipse.jface.viewers.ColumnWeightData;
导入org.eclipse.jface.viewers.TableViewer;
导入org.eclipse.jface.viewers.TableViewerColumn;
导入org.eclipse.jface.wizard.WizardPage;
导入org.eclipse.swt.swt;
导入org.eclipse.swt.layout.GridData;
导入org.eclipse.swt.layout.GridLayout;
导入org.eclipse.swt.widgets.Composite;
导入org.eclipse.swt.widgets.Label;
导入org.eclipse.swt.widgets.Table;
导入org.eclipse.swt.widgets.TableColumn;
公共类MakeNodeSuccessWizardPage扩展WizardPage{
专用复合顶板;
私人桌面查看器;
私人桌面布局;
公共MakeNodeSuccessWizardPage(){
超级(“MyPage”);
设定所有权(“某些所有权”);
设置消息(“某些消息”);
}
@凌驾
公共void createControl(复合父级){
top=新复合材料(母体,SWT.NONE);
setLayout(新的GridLayout());
设置控制(顶部);
createViewer(顶部);
createHelp();
setPageComplete(假);
}
私有void createHelp(){
复合包装=新复合材料(顶部,SWT.NONE);
setLayout(新的GridLayout(2,false));
setLayoutData(新的GridData(GridData.FILL_HORIZONTAL));
创建第一行(包装器);
创建第二行(包装器);
createThirdRow(包装器);
}
私有void createFirstRow(复合包装器){
//第1栏
标签绿色标记=新标签(包装,SWT.NONE);
greenMark.setText(“Cheched”);
//第2栏
标签帮助=新标签(包装器,SWT.NONE);
setText(“表示新创建了一个节点”);
}
私有void createSecondRow(复合包装器){
//第1栏
标签交叉标记=新标签(包装,SWT.NONE);
crossMark.setText(“未选中”);
//第2栏
标签帮助=新标签(包装器,SWT.NONE);
setText(“指示节点是现有的,因此保持不变”);
}
私有void createThirdRow(复合包装器){
//第1栏
标签刷新=新标签(包装,SWT.NONE);
refresh.setText(“refresh”);
标签帮助=新标签(包装器,SWT.NONE);
help.setText(“如果创建了任何节点,包导航器中选定的服务器节点将自动刷新”);
}
私有void createViewer(复合父级){
tableLayout=新的TableColumnLayout();
//需要一个仅包含表查看器的单独组合
复合表成分=新复合物(母体,SWT.NONE);
tableComp.setLayout(tableLayout);
tableComp.setLayoutData(新网格数据(SWT.FILL,SWT.FILL,true,true));
查看器=新的TableViewer(tableComp、SWT.H|U卷轴| SWT.V|U卷轴| SWT.BORDER);
createColumns(父级、查看器);
final Table Table=viewer.getTable();
表.setheadervible(true);
表.setLinesVisible(真);
setContentProvider(新的ArrayContentProvider());
//布局查看器
GridData GridData=新的GridData();
gridData.verticalAlignment=gridData.FILL;
gridData.horizontalSpan=2;
gridData.grabExcessHorizontalSpace=true;
gridData.grabExcessVerticalSpace=true;
gridData.horizontalAlignment=gridData.FILL;
viewer.getControl().setLayoutData(gridData);
}
公共TableViewer getViewer(){
返回查看器;
}
//这将为表创建列
私有void createColumns(最终复合父级、最终TableViewer){
TableViewerColumn col=createTableViewerColumn(“名称”,100,0);
col.setLabelProvider(新ColumnLabelProvider(){
@凌驾
公共字符串getText(对象元素){
返回(字符串)元素;
}
});
tableLayout.setColumnData(col.getColumn(),新ColumnWeightData(100));
}
private TableViewerColumn createTableViewerColumn(字符串标题、整数绑定、最终整数列号){
最终TableViewerColumn viewerColumn=新的TableViewerColumn(查看器,SWT.LEAD);
final TableColumn column=viewerColumn.getColumn();
列.setText(标题);
column.setWidth(绑定);
column.setResizeable(true);
column.setMoveable(true);
柱设置对齐(SWT中心);
返回viewerColumn;
}
@凌驾
公共void集合可见(布尔可见){
如果(可见){
Set components=new HashSet();
添加(“在混乱中,也有机会”);
添加(“远程工作是/将是新趋势”);
添加(“这些年,所有这些记忆,都是你。你拉着我度过了时光。”);
添加(“我不会死,不会在这里,不会现在,永远不会…”);
添加(“死亡是敬畏之路”);
添加(“工作中取得了进展”);
添加(“死亡”)