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.
Andrey Kuznetsov - 30 Jan 2005 11:19 GMT
> 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?
yes
> 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.
create JWindow with JFrame as owner and add to it you JLabel..
JWindow will be always on top.

Signature
Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Paul van Rossem - 31 Jan 2005 07:36 GMT
> Hi everyone,
>
[quoted text clipped - 10 lines]
>
> Thanks for any pointers.
Why don't you use tooltips? If I understand your problem correctly, this
would be exactly what you need. And you don't have to re-invent the
wheel, keeping things consistent for your users.
Tooltips can be generated dynamically by overriding String
JComponent.getToolTipText(MouseEvent), if that's what you are concerned
about. And if you need to you can even format them with HTML.
<http://java.sun.com/docs/books/tutorial/uiswing/components/tooltip.html>
Paul.