• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving components inserted into a JTextPane

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The application I am writing inserts JLabels into a JTextPane using the insertComponent method. I need to be able to retrieve the JLabel at any given position within the JTextPane. Does anyone know how to accomplish this?
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing the same problem. I insert an icon into JTextPane using insertIcon() method. But how do i retrieve it.
I posted this question..but no reply.
Did u solve it??
...saj
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solving this was really a pain... JTextPane has Container as an ancestor, so using getComponentAt( x, y ) was a pretty obvious choice to use... However, it kept returning some stupid inner class of javax.swing.text.ComponentView as the component insteand of the JLabel... This inner class was not documented in the APIs, so I used reflection on it to figure out which methods it had. Somewhere down the line it also inherited from container, so I tried getComponents()... sure enough, I was able to pull the JLabel out of it!

And Sajee, it looks like you can solve your problem by adding the ImageIcon to a JLabel and then using insertComponent() instead of adding the Icon directly to the JTextPane!

Anyway, here's the code I finally ended up with that was able to pull JLabels out of a JTextPane... it's not great, but hopefully will illustrate what you need to do...



HTH,
-Nate
 
reply
    Bookmark Topic Watch Topic
  • New Topic