0

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
khattak
  • 65
  • 7
  • Are you sure the GIF files are correctly pointing to smile or sad correctly? – prasad_ Jan 14 '19 at 01:58
  • 1
    1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. [This answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). – Andrew Thompson Jan 14 '19 at 04:44

1 Answers1

0

thank you everyone. its sorted out. it was caching the last icon so what i did i moved the style variable to respect switch statement and it worked fine. closing this.

khattak
  • 65
  • 7