I have a multiline textarea. I need to show certain lines as error. I
was
planning to color them in red.The requirement is lets say I have a
textarea with n lines. I want to highlight some lines based on line
numbers. Imagine I have the error lines in a int[].
I started with JEditorPane and using html to highlight. but there
are many difficulties:
1. I need to scan through the whole text and find which text
corresponds to the line numbers, and inset the tags at those offsets.
2. for getting the actual document, again I need to parse and remove
the tags.
Any better way of doing this?
|
|
0
|
|
|
|
Reply
|
amitdev (18)
|
6/8/2006 12:49:27 AM |
|
Found a way myself. Let me know if there is an efficent way of doing
this.If I need to highlight line k in a textpane:
Element e = document.getRootElements()[0].getElement(k);
document.setCharacterAttributes(e.getStartOffset(), e.getEndOffset() -
e.getStartOffset(), as, true);
where as is the attributeset having the right color.
amitdev@gmail.com wrote:
> I have a multiline textarea. I need to show certain lines as error. I
> was
> planning to color them in red.The requirement is lets say I have a
> textarea with n lines. I want to highlight some lines based on line
> numbers. Imagine I have the error lines in a int[].
> I started with JEditorPane and using html to highlight. but there
> are many difficulties:
> 1. I need to scan through the whole text and find which text
> corresponds to the line numbers, and inset the tags at those offsets.
> 2. for getting the actual document, again I need to parse and remove
> the tags.
>
> Any better way of doing this?
|
|
0
|
|
|
|
Reply
|
amitdev
|
6/8/2006 10:59:04 PM
|
|