:(
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:
int oldLength = chat.getText().length();
chat.setSelectionStart(oldLength);
chat.setText(chat.getText() + str+"\n");
chat.setSelectionEnd(chat.getText().leng th());
chat.setCharacterAttributes(redText, false);
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?
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:
int oldLength = chat.getText().length();
chat.setSelectionStart(oldLength);
chat.setText(chat.getText() + str+"\n");
chat.setSelectionEnd(chat.getText().leng
chat.setCharacterAttributes(redText, false);
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?
