Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » ExpandItem(ExpandItem: parent layout appears incorrect on Expand/Collaps events)
ExpandItem [message #1782141] Mon, 19 February 2018 07:04 Go to next message
Eclipse UserFriend
Hello,

I have the following snipped with a GridLayout and two Composites, an upper one and a lower one. The lower one is an ExpandBar with one Item. When the Item is collapsed, the parent should layout so that the available vertical space is grabbed by the upper composite. Correspondingly, when the the Item is expanded, it should get the space it needs.
package probieren.julia.layout;
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.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class MyLayoutExpandBar {
	public static void main (String [] args) {
		final Display display = new Display ();
		Shell shell = new Shell (display);
		shell.setLayout (new FillLayout());

		final Composite parent = new Composite (shell, SWT.BORDER);
		parent.setLayout(new GridLayout());
		
		Composite comp = new Composite(parent, SWT.BORDER);
		comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		
		ExpandBar expandBar = new ExpandBar (parent, SWT.V_SCROLL);
		expandBar.setLayoutData(new GridData(SWT.FILL, SWT.END, true, false));

		ExpandItem item = new ExpandItem (expandBar, SWT.NONE);
		item.setText("Expand Item");
		item.setHeight(200);
		item.setExpanded(true);

		/* Listener */
		expandBar.addListener(SWT.Expand, new Listener() {
			
			@Override
			public void handleEvent(Event event) {
				display.asyncExec(new Runnable() {
					
					@Override
					public void run() {
						parent.layout();
					}
				});
			}
		});
		expandBar.addListener(SWT.Collapse, new Listener() {
			
			@Override
			public void handleEvent(Event event) {
				display.asyncExec(new Runnable() {
					
					@Override
					public void run() {
						parent.layout();
					}
				});
			}
		});
		shell.setText("Shell");
		shell.setSize(300, 300);
		shell.open ();

		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ())
				display.sleep ();
		}
		display.dispose ();
	}
}

On Windows the snipped works, but on Linux (in my case Ubuntu 16.04 LTS) the size of the ExpandBar after a Collaps/Expand event is not yet updated when parent.layout() is called. So the hight of the ExpandBar is small when it is expanded and large when it is collapsed (just opposite as it should!).
After the parent is resized, e.g. by resizing the shell, the layout appears correctly.

Does anyone know, how to make this work correctly?
Thanks,
Julia

[Updated on: Mon, 19 February 2018 07:07] by Moderator

Re: ExpandItem [message #1782196 is a reply to message #1782141] Tue, 20 February 2018 06:08 Go to previous message
Eclipse UserFriend
Just noticed that this question is posted in the wrong forum, sorry.
I'm about to post it in the SWT forum (right now the eclipse server somehow doesn't let me, I'll try later again).
Previous Topic:progress bar action
Next Topic:3.x to 4.x migration confirmation
Goto Forum:
  


Current Time: Fri Jul 25 09:33:14 EDT 2025

Powered by FUDForum. Page generated in 0.06569 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top