Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Label.setImage() and Lable.setText()
Label.setImage() and Lable.setText() [message #450745] Thu, 17 February 2005 15:33 Go to next message
Eclipse UserFriend
Originally posted by: johns.atwork.comhem.se

Hi!

I am new to SWT.

I have been reading a book on SWT and have started
going through the examples and have a question about
the behavior of Label. (or maybe the question applies to Shell)

As I understand it, one can use setImage() and/or setText()
to set these attributes of a Label and the last one set will
be the one displayed. Text will be displayed if the order is
...
myLable.setImage(someImage);
myLable.setText("Some text.");
...

and an image will be displayed if the order is
...
myLable.setText("Some text.");
myLable.setImage(someImage);
...

First question: Is my assumtion correct?

The second question has the following setup.

If I start with the following code:

...
String sTextA = "Some text.";
String sTextB = "Some other text.";
...
myLable.setText(sTextA);
myLable.setImage(someImage);
...

and then display it I will see the image, someImage.

If this follows later in the code:

...
myLable.setImage(someImage);
myLable.setText(sTextA);
...

the result displayed will be the image, someImage.

The appearent reason for this is that nothing at all
happens when the text being set is an exact match
of the text already there. The intention was to bring
forward the text but this cannot be done in that manner.

I discoverd this because the following:

...
myLable.setImage(someImage);
myLable.setText(sTextB);
...

results in sTextB being displayed.
(because sTextB is a different string from sTextA).

Note that if:

String sTextB = "Some text."; (i.e the same string as sTextA)

then the result will still be the image, someImage, being displayed.

Second question: Is that the correct behavior?

Thanks in advance!

/John
Re: Label.setImage() and Lable.setText() [message #450845 is a reply to message #450745] Fri, 18 February 2005 15:13 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
You are right but you shouldn't rely on this behavior. In future, both text
and images may be shown at the same time in a label.

"John S" <johns.atwork@comhem.se> wrote in message
news:cv2dg4$ljp$1@www.eclipse.org...
> Hi!
>
> I am new to SWT.
>
> I have been reading a book on SWT and have started
> going through the examples and have a question about
> the behavior of Label. (or maybe the question applies to Shell)
>
> As I understand it, one can use setImage() and/or setText()
> to set these attributes of a Label and the last one set will
> be the one displayed. Text will be displayed if the order is
> ...
> myLable.setImage(someImage);
> myLable.setText("Some text.");
> ...
>
> and an image will be displayed if the order is
> ...
> myLable.setText("Some text.");
> myLable.setImage(someImage);
> ...
>
> First question: Is my assumtion correct?
>
> The second question has the following setup.
>
> If I start with the following code:
>
> ...
> String sTextA = "Some text.";
> String sTextB = "Some other text.";
> ...
> myLable.setText(sTextA);
> myLable.setImage(someImage);
> ...
>
> and then display it I will see the image, someImage.
>
> If this follows later in the code:
>
> ...
> myLable.setImage(someImage);
> myLable.setText(sTextA);
> ...
>
> the result displayed will be the image, someImage.
>
> The appearent reason for this is that nothing at all
> happens when the text being set is an exact match
> of the text already there. The intention was to bring
> forward the text but this cannot be done in that manner.
>
> I discoverd this because the following:
>
> ...
> myLable.setImage(someImage);
> myLable.setText(sTextB);
> ...
>
> results in sTextB being displayed.
> (because sTextB is a different string from sTextA).
>
> Note that if:
>
> String sTextB = "Some text."; (i.e the same string as sTextA)
>
> then the result will still be the image, someImage, being displayed.
>
> Second question: Is that the correct behavior?
>
> Thanks in advance!
>
> /John
Previous Topic:view tab placement
Next Topic:platform-dependent font size issue
Goto Forum:
  


Current Time: Fri Apr 19 12:40:34 GMT 2024

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

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

Back to the top