Image

Imagejvcam wrote in Imagejava_dev 😡frustrated

:(

Another Java problem ;-)

This chat program (if you remember from my last q)... I'm using a JTextPane with a StyledDocument inside to get the text different colours for each person chatting, having a bit of a prob with setting the colours and them staying the right colour.



A message comes from the server and is displayed in the chat box. What then happens is the text is selected and the colour changed using:

<br /> int oldLength = chat.getText().length();<br /><br /> chat.setSelectionStart(oldLength);<br /> chat.setText(chat.getText() + str+"\n");<br /> chat.setSelectionEnd(chat.getText().leng<wbr />th());<br /><br /> chat.setCharacterAttributes(redText, false);<br />

there's an if statement in there that I've removed (it just checks which colour should be displayed for each person)... It's a bit crude and I'm sure there is an easier way to do it. The problem is that when a new message comes to the chat box, the previous text that have their colours set revert back to being just black (default)... I can't work out why they get reset once a new line comes in and its colour changed... Any ideas?