dierre
dierre

Reputation: 7220

append a style to a JTextPane

Here's my problem. I'm writing an editor which has syntax highlight. Nothing fancy but it does the job. The problem is that I'm implementing error recognition and when I want to add the style to underline the line, I'm overriding the style I had before. Here's a screenshot:

true I'm doing something like this to add the new style:

            if(e.getListaErrori().size()>0){
                jcb.addItem("ERRORS FOUND");
                for(org.univpm.grail.error.Error i:e.getListaErrori()){
                    jcb.addItem(i.getError());
                    Element child = root.getElement(i.getLine()-1);
                    styleRoot.setCharacterAttributes(child.getStartOffset(), i.getInstr().length()-1, ta.getStyle("ErrUnder"), true);
                }
                jcb.setVisible(true);
            }

If I use setCharacterAttributes with the last argument to false we have:

false That is almost what I want. I would like to have the underline of a different color. I realized it's impossibile...but...do you think is there a way to do it?

Upvotes: 2

Views: 203

Answers (1)

camickr
camickr

Reputation: 324207

when I want to add the style to underline the line, I'm overriding the style I had before.

Maybe instead of playing with the styles, you can just "highlight" the text by using a highlighter. Rectangle Painter shows how to create a custom rectangle highlight. You should be able to change the code easily to just use a line highlight.

Upvotes: 3

Related Questions