Why does the table viewer's horizontal scrolling disappears once the wizard page is brought back to its normal size post expansion?

好久不见. 提交于 2020-03-25 18:20:50

问题


I have a table viewer displayed on a wizard page. The first time the page is displayed, as seen both horizontal and vertical scroll bars are present as yellow highlighted shown in below image-

The horizontal scroll bar disappears once the wizard page is expanded in both directions and then brought back to its normal size. As seen below, only the vertical scroll bar is there, but the horizontal scroll bar is lost.

How can I bring back the horizontal scroll bar?

The code snippet to simulate the above example is as below-

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);
    }
}

来源:https://stackoverflow.com/questions/60836496/why-does-the-table-viewers-horizontal-scrolling-disappears-once-the-wizard-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!