This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 10747

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
It's not a secret anymore!