This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I've got a problem with Style Attributes not always colouring stuff.
I'm simplifying the code here, my set up is pretty complex, but I think the snippet below is a good representation of the problem.
I have the following method:
This outputs the location of the word and then colours it in blue. Everytime I call it, the values of the "word" value are different, as I want to colour different parts of the document.
When I call the above method several times within a second or so, MOST of the time, it colours the text correctly.
But sometimes, it doesn't.
I know it can find the location of the word just fine, due to the println, I'm confused as to why the changes sometimes dont apply?
Do I need to go back and and look at my code further or is it something to do with StyleConstants/Attributes?
Apologies for not posting exact code - I just have a feeling its not the code but a 'feature' of java doing this.
Maybe you use the same attributes object to colour text with different colors ?
If you have something like this:
if it is the case, you must create individual attributeSet object for each color.
Joined: Dec 30, 2009
Ireneusz, thank you for your response.
Yes, I used the attributes object to colour text with different colours, I am very impressed you thought of that!
However, I still have the same problem.
Here is the method:
If I paste lots of text in, most of the keywords will get coloured blue and most of the normal words will get coloured red.
But some words do not get coloured, even though they DO show up in the println.
Did I get the attributes object wrong again or could it be something else?