简体   繁体   中英

SWT / JFace Scrollview not scrolling

I have two tabs with their own respective views. The tabview itself is in a scrollview. For some reason, the scrollbars don't appear for the larger tab. I set up the (working) tabview like so:

public CustomerTab(Composite arg1, int arg2) throws SQLException {
    super(arg1, arg2);

    layout = new org.eclipse.swt.layout.GridLayout(GridData.FILL_BOTH, false);
    layout.numColumns = 1;
    this.setLayout(layout);

The one, that's not causing the scrollbars to appear, starts like so:

public InvoiceTab(Composite parent, int arg2) throws Exception {

    super(parent, arg2);

    // new gridlayout and asign to this tab
    gridLayout = new org.eclipse.swt.layout.GridLayout(GridData.FILL_BOTH, false);
    gridLayout.numColumns = 3;
    this.setLayout(gridLayout);

In my application, I configure the shell:

@Override protected void configureShell(Shell shell) {

    super.configureShell(shell);
    shell.setSize(1130, 530);
    setShellStyle(SWT.SHELL_TRIM & (~SWT.RESIZE));
}

and create the scrollview this way:

@Override protected Control createContents (Composite parent) {

    scrolledComp = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    mainContent = new Composite(scrolledComp, SWT.NONE);
    mainContent.setLayout(new FillLayout());

    mainTabView = null;
    mainTabView = new MainTabView(mainContent);

    scrolledComp.setContent(mainContent);
    scrolledComp.setExpandHorizontal(true);
    scrolledComp.setExpandVertical(true);
    scrolledComp.setMinSize(1100, 500);

    return mainTabView;
}

What happens, is that the scrollview just displays as far the 500 go, but no content below, no scrollbars. Can anybody see, what I'm doing wrong?

Thanx in advance, Marcus

Since you set you minimum height manually to 500, the ScrolledComposite doesn't know better.

You should use the "real" size of the content as minimum size. You can use the following code:

scrolledComp.setContent(mainContent);
scrolledComp.setExpandHorizontal(true);
scrolledComp.setExpandVertical(true);
scrolledComp.setMinSize(mainContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM