Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ExpandBar how multiline Label layout
ExpandBar how multiline Label layout [message #511233] Sun, 31 January 2010 10:48 Go to next message
steven is currently offline steven
Messages: 7
Registered: August 2009
Location: China
Junior Member

Hi all,

I encounter a problem and can't deal with it.

I wanna create a ExpandBar and a multi-line Label to fill it as an ExpandItem like this:

-------------------------------------
System Info |
-------------------------------------
System Name: XX |
Details : multiline.. |
text..... |
-------------------------------------


When I fill the Wrap lable in to the ExpandItem I found it can't be shown property, when I change the width of the ExpandBar,
The ExpandItem can't compute the correct size.


import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
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.Label;
import org.eclipse.swt.widgets.Shell;

public class Main {
 // public class Main {

 public static void main(String[] args) {

		Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		shell.setSize(400, 400);
		
		SashForm sf = new SashForm(shell, SWT.HORIZONTAL);
		Composite lCom = new Composite(sf, SWT.NONE);
		lCom.setLayout(new FillLayout());
		
		Composite rCom = new Composite(sf, SWT.NONE);
		rCom.setLayout(new FillLayout());
		
		
		
		ExpandBar expandBar = new ExpandBar(lCom, SWT.NONE);
		final ExpandItem expandItem = new ExpandItem(expandBar, SWT.NONE);
		
		final Label label = new Label(expandBar, SWT.WRAP);
		label.setText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
		expandItem.setHeight(label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
		expandItem.setControl(label);

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

}



So what should I do , Thanks
Re: ExpandBar how multiline Label layout [message #511456 is a reply to message #511233] Mon, 01 February 2010 06:10 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2148
Registered: July 2009
Senior Member
This should do what you want...

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(400, 400);
SashForm sf = new SashForm(shell, SWT.HORIZONTAL);
Composite lCom = new Composite(sf, SWT.NONE);
lCom.setLayout(new FillLayout());
Composite rCom = new Composite(sf, SWT.NONE);
rCom.setLayout(new FillLayout());
final ExpandBar expandBar = new ExpandBar(lCom, SWT.NONE);
final ExpandItem expandItem = new ExpandItem(expandBar, SWT.NONE);
final Label label = new Label(expandBar, SWT.WRAP);
label.setText("a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa
aaaaaaaaa aaaaaaaaaaa");
//expandItem.setHeight(label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
expandBar.addListener(SWT.Resize, new Listener() { // <---
public void handleEvent(Event event) {
Point size = label.computeSize(expandBar.getClientArea().width,
SWT.DEFAULT);
expandItem.setHeight(size.y);
}
});
expandItem.setControl(label);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant


"steven" <boysuheng@gmail.com> wrote in message
news:hk48o0$1gk$1@build.eclipse.org...
> Hi all,
>
> I encounter a problem and can't deal with it.
>
> I wanna create a ExpandBar and a multi-line Label to fill it as an
ExpandItem like this:
>
> -------------------------------------
> System Info |
> -------------------------------------
> System Name: XX |
> Details : multiline.. |
> text..... |
> -------------------------------------
>
>
> When I fill the Wrap lable in to the ExpandItem I found it can't be shown
property, when I change the width of the ExpandBar,
> The ExpandItem can't compute the correct size.
>
>
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.SashForm;
> import org.eclipse.swt.layout.FillLayout;
> 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.Label;
> import org.eclipse.swt.widgets.Shell;
>
> public class Main {
> // public class Main {
>
> public static void main(String[] args) {
>
> Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> shell.setSize(400, 400);
>
> SashForm sf = new SashForm(shell, SWT.HORIZONTAL);
> Composite lCom = new Composite(sf, SWT.NONE);
> lCom.setLayout(new FillLayout());
>
> Composite rCom = new Composite(sf, SWT.NONE);
> rCom.setLayout(new FillLayout());
>
>
>
> ExpandBar expandBar = new ExpandBar(lCom, SWT.NONE);
> final ExpandItem expandItem = new ExpandItem(expandBar, SWT.NONE);
>
> final Label label = new Label(expandBar, SWT.WRAP);
>
label.setText(" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa a
aaaa");
> expandItem.setHeight(label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
> expandItem.setControl(label);
>
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> }
>
>
>
> So what should I do , Thanks
Re: ExpandBar how multiline Label layout [message #511471 is a reply to message #511456] Mon, 01 February 2010 11:42 Go to previous message
steven is currently offline steven
Messages: 7
Registered: August 2009
Location: China
Junior Member

Waw ! Grant Gayed, thank you very much.

I really do think the Wrap Label in swt is a troublesome thing when involved into Layout.


Thanks & Best Regards,
Steven
Previous Topic:MenuItem doesn't send selection event the 2nd time around
Next Topic:TrayItem and ToolTip bug on Ubuntu
Goto Forum:
  


Current Time: Fri Aug 22 23:43:35 EDT 2014

Powered by FUDForum. Page generated in 0.02098 seconds