File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Style Attributes not always working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Style Attributes not always working" Watch "Style Attributes not always working" New topic
Author

Style Attributes not always working

Clive Mercer
Greenhorn

Joined: Dec 30, 2009
Posts: 10
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

Joined: Jun 21, 2008
Posts: 423
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

Joined: Dec 30, 2009
Posts: 10
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

Joined: Jun 13, 2009
Posts: 2172
    
    7
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Style Attributes not always working