Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Problem with Label.setText() and StackLayout
Problem with Label.setText() and StackLayout [message #43575] Tue, 28 August 2007 13:56 Go to next message
Magnus Konze is currently offline Magnus KonzeFriend
Messages: 35
Registered: July 2009
Member
Hi!
I have a strange problem with Label and StackLayout:
I'm using StackLayout and a Composite with a Label. But i can only use
Label.setText() if its Composite is the first topControl of the
StackLayout. If i set it later as topControl, the Label is not repainted
(but getText() returns the correct value).

I created a small demo-Composite, where you can see the problem:
There are two equal Composites on a StackLayout, each with a Label, but
only on the first one you can add Text to the Label. If you exchange the
Label with a Text, it works fine:


import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class StackLayoutTestComposite extends Composite{
private StackLayout stackLayout = new StackLayout();
private Composite composite1, composite2;

public StackLayoutTestComposite(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(1, false));
Button switchButton = new Button(this, SWT.NONE);
switchButton.setText("switch Composite");

final Composite composite = new Composite(this, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
composite.setLayout(stackLayout);
composite1 = createComposite(composite, "1");
composite2 = createComposite(composite, "2");
stackLayout.topControl = composite1;
composite.layout();

switchButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (stackLayout.topControl == composite1) {
stackLayout.topControl = composite2;
} else {
stackLayout.topControl = composite1;
}
composite.layout();
}
});

}


private Composite createComposite(Composite parent, String startValue) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
final Label label = new Label(composite, SWT.NONE);
label.setText(startValue);
GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
Button button = new Button(composite, SWT.BORDER);
button.setText("add text to Label");
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
label.setText(label.getText()+"x");
}
});
return composite;
}
}
Re: Problem with Label.setText() and StackLayout [message #44316 is a reply to message #43575] Sat, 01 September 2007 21:42 Go to previous message
Benjamin Muskalla is currently offline Benjamin MuskallaFriend
Messages: 237
Registered: July 2009
Senior Member
Hi Magnus,

seems very strange. You could please file a bug against RWT so we can
track that?

Thanks
Benny

Magnus Konze wrote:
> Hi!
> I have a strange problem with Label and StackLayout:
> I'm using StackLayout and a Composite with a Label. But i can only use
> Label.setText() if its Composite is the first topControl of the
> StackLayout. If i set it later as topControl, the Label is not repainted
> (but getText() returns the correct value).
>
> I created a small demo-Composite, where you can see the problem:
> There are two equal Composites on a StackLayout, each with a Label, but
> only on the first one you can add Text to the Label. If you exchange the
> Label with a Text, it works fine:
>
>
> import org.eclipse.jface.layout.GridDataFactory;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.StackLayout;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Label;
>
> public class StackLayoutTestComposite extends Composite{
> private StackLayout stackLayout = new StackLayout();
> private Composite composite1, composite2;
>
> public StackLayoutTestComposite(Composite parent, int style) {
> super(parent, style);
> setLayout(new GridLayout(1, false));
> Button switchButton = new Button(this, SWT.NONE);
> switchButton.setText("switch Composite");
>
> final Composite composite = new Composite(this, SWT.NONE);
> GridDataFactory.fillDefaults().grab(true,
> false).applyTo(composite);
> composite.setLayout(stackLayout);
> composite1 = createComposite(composite, "1");
> composite2 = createComposite(composite, "2");
> stackLayout.topControl = composite1;
> composite.layout();
>
> switchButton.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> if (stackLayout.topControl == composite1) {
> stackLayout.topControl = composite2;
> } else {
> stackLayout.topControl = composite1;
> }
> composite.layout();
> }
> });
>
> }
>
>
> private Composite createComposite(Composite parent, String
> startValue) {
> Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new GridLayout(1, false));
> final Label label = new Label(composite, SWT.NONE);
> label.setText(startValue);
> GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
> Button button = new Button(composite, SWT.BORDER);
> button.setText("add text to Label");
> button.addSelectionListener(new SelectionAdapter(){
> public void widgetSelected(SelectionEvent e) {
> label.setText(label.getText()+"x");
> }
> });
> return composite;
> }
> }
>
>
Previous Topic:ServletContext is null
Next Topic:Re: How to show a MessageDialog in a web browser when an event occoured in the backround thread
Goto Forum:
  


Current Time: Sat Jun 10 05:45:13 GMT 2023

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

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

Back to the top