I am trying to build a chat system; a simple one while learning JTextPane
and document.
I have chat like this in text file:
Time:12:14:56 Name:Asad Message:Hello danish :) :)
Time:12:22:59 Name:danish Message:Hi asad :(
I have made elements perfectly and getting output as well except emojis. What I am experiencing is that last style icon is coming on all emojis like in current chat its sad smiley.
Here is my code for icon setting:
Style happylabelStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
Icon icon = new ImageIcon("smile_happy.gif");
StyleConstants.setIcon(happylabelStyle, icon);
Style sadlabelStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
Icon icon1 = new ImageIcon("smile_sad.gif");
StyleConstants.setIcon(sadlabelStyle, icon1);
And here is my switch
statement which perfectly executes while reading text:
case SMILE_HAPPY:
doc.insertString(doc.getLength(), "Ignored",
happylabelStyle);
break;
case SMILE_SAD:
doc.insertString(doc.getLength(), "Ignored",
sadlabelStyle);
break;
Not sure where I am doing wrong. It will be much appreciated if someone can pin point the issue or provide any link which i can go through to fix this.