Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Style Attributes not always working

 
Clive Mercer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks, long time lurker

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.

Thanks in advance,

Clive
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Clive Mercer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks again,

Clive


EDIT:
Here is a screenshot of the problem:
 
Rob Camick
Ranch Hand
Posts: 2555
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just have a feeling its not the code but a 'feature' of java doing this.


Funny, I have the opposite feeling.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic