ExpandBar how multiline Label layout [message #511233] |
Sun, 31 January 2010 15:48 |
|
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 11:10 |
Grant Gayed Messages: 2150 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03766 seconds