fun with fonts [message #460577] |
Wed, 31 August 2005 19:26 |
Eclipse User |
|
|
|
Originally posted by: gilbert.pilz.bea.com
I am fairly new to SWT and I need some help with the following problem.
I'm trying to write a simple group-chat application and I want the name
of the person that "says" something to appear in bold while the thing
that they say appears in a normal font. For example:
gil: I thought this would be easier than it appears to be.
alice: I'm not sure.
In the above sentences "gil" and "alice" would appear in bold. Right now
I am using a simple Text widget to display the contents of the chat, but
it seems to me that all the text in the textbox has to be of the same
font. Does anyone have any suggestions?
- gil
|
|
|
Re: fun with fonts [message #460579 is a reply to message #460577] |
Wed, 31 August 2005 19:29 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
To intermix fonts and colors on text you need to use a StyledText
instead of Text.
--
Thanks,
Rich Kulp
|
|
|
Re: fun with fonts [message #460583 is a reply to message #460579] |
Wed, 31 August 2005 19:46 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
news:df50f9$q5$2@news.eclipse.org...
> To intermix fonts and colors on text you need to use a StyledText instead
> of Text.
>
Does StyledText let you change fonts?
I thought all you could change were attributes (bold, italic, underline,
strikethrough and colors).
---
Sunil
|
|
|
Re: fun with fonts [message #460586 is a reply to message #460583] |
Wed, 31 August 2005 20:45 |
Eclipse User |
|
|
|
Originally posted by: gilbert.pilz.sbc-guesstherest.net
Sunil Kamath wrote:
> "Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
> news:df50f9$q5$2@news.eclipse.org...
>
>>To intermix fonts and colors on text you need to use a StyledText instead
>>of Text.
>>
>
> Does StyledText let you change fonts?
> I thought all you could change were attributes (bold, italic, underline,
> strikethrough and colors).
> ---
> Sunil
Rich, thanks for the quick help! I'll play around with this and post my
results.
Sunil, FWIW the documentation lists "setFont()" as a method of
StyledText. I'll let you know how it goes . . .
- g
|
|
|
Re: fun with fonts [message #460588 is a reply to message #460586] |
Wed, 31 August 2005 21:05 |
Eclipse User |
|
|
|
Originally posted by: gilbert.pilz.sbc-guesstherest.net
Gilbert Pilz wrote:
> Rich, thanks for the quick help! I'll play around with this and post my
> results.
So the first thing I noticed when replacing my Text widget with a
StyledText widget is that the control no longer scrolls automatically
when I add lines via the append() method. Here is the line where I
create the StyledText instance:
StyledText roomText = new StyledText(s, SWT.MULTI | SWT.BORDER |
SWT.WRAP | SWT.V_SCROLL);
According to the documentation, V_SCROLL is valid for any Scrollable and
any subclasses (of which StyledText is one).
- g
|
|
|
Re: fun with fonts [message #460592 is a reply to message #460586] |
Wed, 31 August 2005 23:23 |
Eclipse User |
|
|
|
Originally posted by: gilbert.pilz.sbc-guesstherest.net
Gilbert Pilz wrote:
> Rich, thanks for the quick help! I'll play around with this and post my
> results.
So here's what I have figured out so far:
1.) You can use StyledText to display text in NORMAL and BOLD (no
italics) and different colors. You cannot use it to display text of
different point sizes or from different families (e.g. Arial and Veranda).
2.) The documentation for StyledText and StyleRange is pretty abysmal.
They use words like "offset" and "index" all over the place without
explaining what they really mean. FYI the characters in a StyledText
widget start at offset 0. StyledText.getCharCount() gets you the number
of characters currently in the widget which equals the offset of the
next character to be written. So if you want to write out some new text
in bold something like this works:
String textToWrite = "something or other";
int newOffset = styledText.getCharCount();
// append the text
styledText.append(textToWrite);
// make it bold
styledText.setStyleRange(new StyleRange(newOffset,
textToWrite.length(),
null,
null,
SWT.BOLD));
3.) I worked around the non-scrolling problem by calling
invokeAction(ST.PAGE_DOWN) every time I appended text to the widget.
This seems rather extreme, but invokeAction(ST.LINE_DOWN) didn't seem to
do the trick for some reason.
- g
|
|
|
Re: fun with fonts [message #460598 is a reply to message #460586] |
Thu, 01 September 2005 04:07 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"Gilbert Pilz" <gilbert.pilz@sbc-guesstherest.net> wrote in message
news:df54sq$7dr$1@news.eclipse.org...
> Sunil Kamath wrote:
>> "Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
>> news:df50f9$q5$2@news.eclipse.org...
>>
>>>To intermix fonts and colors on text you need to use a StyledText instead
>>>of Text.
>>>
>>
>> Does StyledText let you change fonts?
>> I thought all you could change were attributes (bold, italic, underline,
>> strikethrough and colors).
>> ---
>> Sunil
>
> Rich, thanks for the quick help! I'll play around with this and post my
> results.
>
> Sunil, FWIW the documentation lists "setFont()" as a method of StyledText.
> I'll let you know how it goes . . .
>
Yes, you can call setFont() (as you can do for all widgets), but that
changes the font for all the text in the widget.
You can't have multiple fonts at the same time.
---
Sunil
|
|
|
|
Powered by
FUDForum. Page generated in 0.03814 seconds