• 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

Displaying a "floating" JLabel

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I've got a JTextArea that serves as a very basic XSLT editor. One of its functions is to allow the user to input elements via accelarators (e.g. Ctrl+Shift+t inserts a <xsl:template> element). Is it possible to display a component, such as a JLabel, at the position of the caret in the JTextArea? The intention is to populate it with information about what letter inserts what element)

Because my JFrame's LayoutManager is set to BorderLayout, I don't see how I'd be able to position the JLabel at specific x,y coordinates relative to the caret.

Thanks for any pointers.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would consider a JPopupMenu, a JDialog, a JWindow or possibly an overlay approach such as a glass pane or a non–opaque JPanel added above the JTextArea with an OverlayLayout as options. The last two options have some extra overhead regarding event routing, especially the glass pane. But they can give an elegant affect. You can use the JComponent method modelToView to convert from the caret position in the document to a point on the component.
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic