Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:02:57+00:00 2026-06-17T12:02:57+00:00

I’m creating an application in Java and SWT and I have a problem. I

  • 0

I’m creating an application in Java and SWT and I have a problem. I want to put ExpandBar into GridLayout. Everything is ok while I don’t collapse the expand bar. When I do it, it collpases normally, but the composite isn’t re-layouted. The screen below should explain my problem:

Before collapse:
Before collapse
After collapse:
After collapse

I tried some tricks, like for example:

bar.addExpandListener(new ExpandListener() {
    public void itemExpanded(ExpandEvent e) {
        item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
        gridData2.heightHint = composite.computeSize(SWT.DEFAULT,
                SWT.DEFAULT).y;
        comp.layout(true, true);
    }

    public void itemCollapsed(ExpandEvent e) {
        item0.setHeight(item0.getHeaderHeight());
        gridData2.heightHint = item0.getHeaderHeight();
        comp.layout(true, true);
    }
});

Altough it doesn’t work. Here is SSCCE:

package stackoverflow;

import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;

public class MainWindowSWT extends Window {

    public MainWindowSWT() {
        super((Shell)null);

        setBlockOnOpen(true);
        open();
        Display.getCurrent().dispose();
    }

    @Override
    protected Control createContents(Composite parent) {
        final Composite comp = new Composite(getShell(), 0);

        GridLayout layout = new GridLayout(1, true);
        comp.setLayout(layout);

        Tree tree = new Tree(comp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
        GridData gridData = new GridData();
        gridData.verticalAlignment = GridData.FILL;
        gridData.verticalSpan = 2;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        tree.setLayoutData(gridData);

        final ExpandBar bar = new ExpandBar(comp, SWT.V_SCROLL);
        final Composite composite = new Composite(bar, SWT.NONE);
        GridLayout gridLayout = new GridLayout();
        gridLayout.verticalSpacing = 10;
        composite.setLayout(gridLayout);
        Button button = new Button(composite, SWT.PUSH);
        button.setText("SWT.PUSH");
        final ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0);
        item0.setText("Test");
        item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
        item0.setControl(composite);

        item0.setExpanded(true);

        final GridData gridData2 = new GridData();
        gridData2.horizontalAlignment = GridData.FILL;
        gridData2.grabExcessHorizontalSpace = true;
        bar.setLayoutData(gridData2);

        return parent;
    }
}

Ubuntu 12.04.1 amd64, SWT 3.7.2.

Thanks in advance.

// Btw: I don’t want to resize shell. I want to resize the tree above the expand bar.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:02:59+00:00Added an answer on June 17, 2026 at 12:02 pm

    I get it working, but I’m not satisfied with this solution…

    bar.addExpandListener(new ExpandAdapter() {
    
        @Override
        public void itemCollapsed(ExpandEvent e) {
            new Thread(new Runnable() {
    
                @Override
                public void run() {
                    try {
                        synchronized (this) {
                            wait(250);
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    Display.getDefault().asyncExec(new Runnable() {
                        public void run() {
                            layout();
    
                        }
                    });
                }
            }).start();
        }
    
        @Override
        public void itemExpanded(ExpandEvent e) {
            new Thread(new Runnable() {
    
                @Override
                public void run() {
                    try {
                        synchronized (this) {
                            wait(250);
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    Display.getDefault().asyncExec(new Runnable() {
                        public void run() {
                            layout();
    
                        }
                    });
                }
            }).start();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have been unable to fix a problem with Java Unicode and encoding. The
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.