Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Child Expand bar doesn't get resized when expanded
Child Expand bar doesn't get resized when expanded [message #1368899] Tue, 20 May 2014 10:25
Vel R is currently offline Vel RFriend
Messages: 1
Registered: May 2014
Junior Member
Hi, I am new to SWT. I ran into a problem while trying to add Child Expand Bar to the Parent expand bar. Its more like a tree Structure. While trying to expand the Child expand Item the Parent doesn't get resized.Tried to set the height of the parent using layout options,setHeight. It doesn't work for me. I am doing some mistake with the layout and Layout Data.

Can anyone tell me what is the mistake i am doing?

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.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Shell;

public class ExpandBarWithChild extends Composite{

private ExpandBar bar = null;
private ExpandItem parentItem;

public ExpandBarWithChild(Composite parent, int style) {
super(parent, style);
GridLayout gridLayout = new GridLayout(1, false);

public static void main(String[] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
shell.setText("Expand Bar Window");
Composite parentComposite = new Composite(shell, SWT.NONE);
parentComposite.setLayout(new FillLayout());
ExpandBarWithChild testNewEIObj = new ExpandBarWithChild(parentComposite, SWT.NONE);
testNewEIObj.setLayout(new FillLayout());
testNewEIObj.createExpandBar(shell, display);

public void createExpandBar(Shell shell,Display display){
bar = new ExpandBar(this, SWT.NONE | SWT.V_SCROLL);
final Composite sectionContainer = new Composite(bar, SWT.NONE);
sectionContainer.setLayout(new FillLayout());
ExpandItem section = new ExpandItem(bar, SWT.NONE, 0);
this.parentItem = section;

ExpandBar bar1 = new ExpandBar(sectionContainer, SWT.NONE );
final Composite sectionContainer1 = new Composite(bar1, SWT.NONE);

ExpandBar bar2 = new ExpandBar(sectionContainer, SWT.NONE );
final Composite sectionContainer2 = new Composite(bar2, SWT.NONE);

Button btn = new Button(sectionContainer1, SWT.PUSH);

Button btn2 = new Button(sectionContainer2, SWT.PUSH);

final ExpandItem section1 = new ExpandItem(bar1, SWT.NONE, 0);
section1.setHeight(sectionContainer1.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);

ExpandItem section2 = new ExpandItem(bar2, SWT.NONE, 0);
section2.setHeight(sectionContainer2.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);

sectionContainer.setLayout(new GridLayout(1, true));
section.setHeight(sectionContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);

bar.addExpandListener(new ExpandListener() {

public void itemCollapsed(ExpandEvent e) {
final ExpandItem item0 = (ExpandItem)e.item;

// if(getParentItem() != null) {
// getParentItem().setHeight(getParentItem().getHeight()-item0.getHeight());
// }


public void itemExpanded(ExpandEvent e) {
ExpandItem item0 = (ExpandItem)e.item;

// if(getParentItem() != null) {
// getParentItem().setHeight(getParentItem().getHeight()+item0.getHeight());
// }



shell.setSize(400, 350);;

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



public static GridData getFullGridData(boolean isParent) {
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
return gridData;

public ExpandItem getParentItem() {
return parentItem;

public void setParentItem(ExpandItem parentItem) {
this.parentItem = parentItem;
Previous Topic:SWT Browser - Setting Accept-Language header dont work propertly
Next Topic:String length limit of GC.textExtent() under Win32
Goto Forum:

Current Time: Thu Nov 26 00:41:23 GMT 2015

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

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