File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes drawChars and onclick Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "drawChars and onclick" Watch "drawChars and onclick" New topic

drawChars and onclick

Robert Kennedy
Ranch Hand

Joined: Jun 27, 2008
Posts: 63

Is it possible t o add an onclick handler (via a mask or directly to the text) to text rendered via drawChars.

if not how would i render a JLabel component at the precise coordinates as the drawChars woudl have rendered.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10825

One possible way.
When you invoke drawChars, compute and store int bounds as a Rectangle.
Add a mouse listener to the container on which the chars are drawn
When the user clicks, check if the click was inside any of the rectangles

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: drawChars and onclick
jQuery in Action, 3rd edition