[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] StyledText Widget multiple styles
|
The snippet below sets two different styles for different parts of the
text.
Questions about how to use SWT should be posted on the
eclipse.platform.swt newsgroup. This mailing list is intended for
discussing the development of SWT.
Perhaps you can post a snippet demonstrating the problem on the newsgroup.
Also, there are two articles about StyledText on the Eclipse website.
Knut
public static void main(String arguments[]) {
Shell shell = new Shell();
Display display = shell.getDisplay();
StyledText text = new StyledText(shell, SWT.NULL);
Color red = new Color(display, 255, 0, 0);
Color blue = new Color(display, 0, 0, 255);
text.setText("Good morning {field:firstNme}");
text.setStyleRange(new StyleRange(0, 13, red, null));
text.setStyleRange(new StyleRange(14, 14, blue, null));
shell.setLayout(new FillLayout());
shell.open();
while (!shell.isDisposed ())
if (!display.readAndDispatch ()) display.sleep ();
red.dispose();
blue.dispose();
}
"Steve Vanspall" <steve@xxxxxxxxxxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx
09/01/2003 03:25 AM
Please respond to platform-swt-dev
To: <platform-swt-dev@xxxxxxxxxxx>
cc:
Subject: [platform-swt-dev] StyledText Widget multiple styles
Hi there,
I am looking at the StyledText widget, and it seems, according to the SPI
to do what I want it to. Only I can't get it to do it, am sure there's
only
a imple error in what I am doing. So hpefully someon can help me.
I what the StyleText to allow me to have different section in the text
that
are coloured blue
The application I am creating is made to create templates according to
some
specification in our database.
Whenever the user creates inserts a field into the template, that field
text
needs to be coloured differently to the rest of the text.
e.g.
Good morning {field:firstNme}
the text '{field:firstNme}' needs to be blue.
I have o problem doing one field like this, but the moment I insert a new
field it takes over as being teh blue text and the previous field goes
back
to being black.
the code that changes the style is shoen below
mainText.setStyleRange(new StyleRange(
pos,
buffer.toString().length(),
blue,
null));
blue - is
a colour set earlier in the code, buffer contains the text
that has been inserted into the text field, and pos is that start position
it was inserted into.
if I do this again, the new text becomes blue and the previous field
reverts
to black.
I have also tried.
StyleRange[] ranges = mainText.getStyleRanges();
StyleRange[] ranges2 = new StyleRange[ranges.length+1];
System.arraycopy(ranges, 0, ranges2, 0, ranges.length);
ranges2[ranges.length] = new StyleRange(
pos,
buffer.toString().length(),
blue,
null);
mainText.setStyleRanges(ranges2);
just in case setStyleRange, was remove all the other styles, but I get teh
same results
I am running on Windows 2000
with the dll's that came with Eclipse 3.0
Has anybody else had this problem, or can someone tell me what I am doing
wrong
Thanks in advance
Steve Vanspall
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev