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 3433820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:37:23+00:00 2026-05-18T07:37:23+00:00

When using the JTextPane method insertIcon() , the javadoc states …This is represented in

  • 0

When using the JTextPane method insertIcon(), the javadoc states "...This is represented in the associated document as an attribute of one character of content."

How do I retrieve the information about my inserted icons? I have tried getCharacterAttributes() which only "Fetches the character attributes in effect at the current location of the caret, or null."

Does a method exist to find all of the attributes in a selection of text, or at a certain index, not just at the current caret position?

Edit
Here is some sample code I pieced together to obtain the filename of an embedded icon.

Element root = jTextPane.getDocument().getDefaultRootElement();
BranchElement current = (BranchElement) root.getElement(0);
if (current != null)
{
    Enumeration children = current.children();
    while (children.hasMoreElements())
    {
        Element child = (Element) children.nextElement();
        if (child.getName().equals("icon"))
        {
            AttributeSet attrSet = child.getAttributes();
            ImageIcon icon = (ImageIcon) StyleConstants.getIcon(attrSet);
            System.err.println(icon.getDescription());
        }
    }
}
  • 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-18T07:37:23+00:00Added an answer on May 18, 2026 at 7:37 am

    Use the Element of the Document to get the attributes:

    Element root = textComponent.getDocument().getDefaultRootElement();
    

    Once you have the root Element you can get the Elements related to your selected text. Start by finding the Element at your start offset and then keep looping through each Element until you reach the end offset.

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

Sidebar

Related Questions

this is kinda overkill for me.. I am using a JTextPane for a chat,
I'm using string builders to append text to my JTextPane, I've set content type
I want to build a console-like output using JTextPane. Therefore I am using a
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
I'm writing a vt100 emulator and I'm using a JTextPane with a DefaultStyledDocument to
Using RestKit 0.10.1, I have objects served similar to this json format: {objects: [
Using System.Diagnostics.EventLog .NET type one can programmatically create logs into the Event Viewer application.
I am using non-editable JTextPane to show some data in HTML format. I have
I have a word wrapping issue when using JTextPane. I think it's my IDE

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.