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.events.ExpandEvent;
import org.eclipse.swt.events.ExpandListener;
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);
setLayout(gridLayout);
}

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.setData("Shell");
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);
bar.setLayoutData(getFullGridData(true));
final Composite sectionContainer = new Composite(bar, SWT.NONE);
sectionContainer.setLayout(new FillLayout());
ExpandItem section = new ExpandItem(bar, SWT.NONE, 0);
section.setText("parent");
this.parentItem = section;

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

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

Button btn = new Button(sectionContainer1, SWT.PUSH);
btn.setText("Button1");
btn.pack();

Button btn2 = new Button(sectionContainer2, SWT.PUSH);
//btn2.setLayoutData(widgetGridDataLayout);
btn2.setText("Button2");
btn2.pack();

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

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


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

bar.addExpandListener(new ExpandListener() {

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

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

}

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

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

}

});

shell.setSize(400, 350);
shell.open();

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

display.dispose();

}


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: Sat Dec 20 12:27:04 GMT 2014

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

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