Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 882251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:23:56+00:00 2026-05-15T12:23:56+00:00

I have a problem with a part of a project i am working on.

  • 0

I have a problem with a part of a project i am working on. I want to display some emoticons using Java Swing, however it won’t allow me to display consecutive identical styles:

This works fine: Smile Sad Grin

This doesn’t work: Smile Smile Smile

I am using Styled Document and have little experience with it. The code is as follows:

       public static void addStylesToDocument(StyledDocument doc) {
        //Initialize some styles.
        ImageIcon laugh = new ImageIcon("laugh.gif");
        ImageIcon sad  = new ImageIcon("sad.gif");
        ImageIcon tongue = new ImageIcon("tongue.gif");
        ImageIcon smile = new ImageIcon("smile.gif");
        ImageIcon cry = new ImageIcon("cry.gif");

        Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

        Style regular = doc.addStyle("regular", def);
        StyleConstants.setFontFamily(def, "SansSerif");

        Style s = doc.addStyle("laugh", def);
        StyleConstants.setIcon(s, laugh);

        Style sads = doc.addStyle("sad", regular);
        StyleConstants.setIcon(sads,sad);


        s = doc.addStyle("tongue", regular);
        StyleConstants.setIcon(s,tongue);


        s = doc.addStyle("smile", regular);
        StyleConstants.setIcon(s,smile);


        s = doc.addStyle("cry", regular);
        StyleConstants.setIcon(s,cry);
    }

^ adding styles to my document

        for (i=0;i<typeOfText.size();i++){
            System.out.println(parsedText.get(i) + " " +  typeOfText.get(i) + " " + i + " " + doc.getLength());
            doc.insertString(doc.getLength(),parsedText.get(i),doc.getStyle(typeOfText.get(i)));
        }   

^ applying the styles to the parsed Text.

So my question is: does Styled Document have a certain property so that when i have same styles one after another it won’t display them correctly?

EDIT: Each text is broken down with String Tokenizer, i get it to parse properly, and apply the appropriate style.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:23:57+00:00Added an answer on May 15, 2026 at 12:23 pm

    Styles will be collapsed if there are multiple styles over consecutive runs of text. That is, multiple runs of text with the same style will be merged into one run of text. It sounds like you are displaying an image based just on the style. You will get multiple images output if you output an image for the number of characters within the given style rather than just the presence of a style.

    Alternatively, instead of having a distinct style for each emoticon, have a general “emoticon” style, and render an appropriate image based on the text. E.g. 🙂 styled with emoticon will render a smiley. And :-):-) will render two smileys. By doing this, you maintain a meaningful relation between the document content and what is presented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Ant tasks in my Eclipse JDT project that I want to
As part of trying to learn hadoop, I'm working on a project using a
I have a problem. Part of my app requires text to be shown in
I have little problem with a replacement of a little part in an url.
i have a problem with my code. foreach (DataRow dr in dt_pattern.Rows) { part
As part of my ecommerce application, I have this interesting problem, I've been trying
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
I am new to .net and have this problem: I want to make installer
For the project I'm working on, we have a desktop program that contacts an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.