Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Wrap Label
Wrap Label [message #480511] Mon, 17 August 2009 12:45 Go to next message
Chris Turner is currently offline Chris TurnerFriend
Messages: 9
Registered: July 2009
Junior Member
I Everyone,

I'm trying to build a Wizard but i'm having problems with the wright
Layout and the Label warping. I want to Show a Label in an Groupbox the
wraps around when it reaches the end of the GroupBox. Now it only gets cut
if it reches the end and the text is not wraped.

Here is my code.

Group g1=new Group(composite, SWT.NONE);
g1.setLayout(new RowLayout(SWT.VERTICAL));
g1.setLayoutData(new RowData(300,120));
g1.setText("Bla");
g1.setSize(300,150);
Label l1= new Label(g1, SWT.WRAP);
l1.setText("~ Some long text ~");
l1.setSize(300,120);
g1.pack();

It would be nice if anybody could point out my error.

Thanks in advance
Chris
Re: Wrap Label [message #480529 is a reply to message #480511] Mon, 17 August 2009 14:22 Go to previous message
Remo Loetscher is currently offline Remo LoetscherFriend
Messages: 18
Registered: July 2009
Junior Member
Hi Chris,

Setting a RowData-Object on the label should solve your wrapping problem:

public class LabelWrapping {
LabelWrapping() {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));

int width = 300, height = 150;

Group g1 = new Group(shell, SWT.NONE);
RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
g1.setLayout(rowLayout);
g1.setLayoutData(new RowData(width, height));
g1.setText("Bla");

Label l1 = new Label(g1, SWT.WRAP);
l1.setLayoutData(new RowData(width - (rowLayout.marginLeft +
rowLayout.marginRight), SWT.DEFAULT));
l1.setText("~ Some long text ~ ~ Some long text ~ ~ Some long text ~ ~
Some long text ~ ~ Some long text ~ ~ Some long text ~");

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

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

public static void main(String[] args) {
new LabelWrapping();
}
}

hth,

Remo

Chris Turner wrote:
> I Everyone,
>
> I'm trying to build a Wizard but i'm having problems with the wright
> Layout and the Label warping. I want to Show a Label in an Groupbox the
> wraps around when it reaches the end of the GroupBox. Now it only gets
> cut if it reches the end and the text is not wraped.
> Here is my code.
>
> Group g1=new Group(composite, SWT.NONE);
> g1.setLayout(new RowLayout(SWT.VERTICAL));
> g1.setLayoutData(new RowData(300,120));
> g1.setText("Bla");
> g1.setSize(300,150);
> Label l1= new Label(g1, SWT.WRAP);
> l1.setText("~ Some long text ~");
> l1.setSize(300,120);
> g1.pack();
>
> It would be nice if anybody could point out my error.
>
> Thanks in advance
> Chris
Previous Topic:readAndDispatch Causing Hang With Browser
Next Topic:newbie question
Goto Forum:
  


Current Time: Fri Apr 19 23:37:25 GMT 2024

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

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

Back to the top