I have an application that allows 2 users (User A + User B) to chat
interactively. Every character User A / User B inputs will be sent to the other
side immediately. Only one of the users is "active" - only characters input by the
"active" user will be sent to the other side. When the "active" user has finished
typing, he/she will press a button to indicate he/she is done and the other side
will become "active".
Characters input by User A / User B will be displayed in an instance of
JTextPane at the other side. An instance of DefaultStyledDocument is used as the
only argument of the constructor that is called to initialize the instance of
JTextPane. JTextPane is used because different colors has to be used to identify
characters input by the 2 users.
Below is some lines of code of the application.
StyledDocument doc = new DefaultStyledDocument();
JTextPane txtReceiveBuffer = new JTextPane(doc);
SimpleAttributeSet attribute = new SimpleAttributeSet();
doc.insertString(doc.getLength(), strUserInput, attribute);
Sometimes a line of characters in the JTextPane will overlap the other line.
(It seems like a transparent layer with some characters is placed in front of
another layer with some characters.) Sometimes the line "behind" will totally
disappear. (It seems like a non-transparent layer with some characters is placed
in front of another layer with some characters.) If a user tries to resize the
frame that contains the JTextPane, sometimes things will be fine again, but
sometimes the problem doesn't go until the application is restarted.
Has anyone ever encountered the same problem? And does anyone get a
solution to this problem?
Thanks in advance.