aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Graphics" Watch "Graphics" New topic
Author

Graphics

Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
If you have a Graphics object that has had text added to it by using the drawString(String, int, int) method, how can I get to this text at a later time?
I am in a situation where I see a JPanel and I can do a getGraphics() on it, giving me a Graphics object. I don't have acces to the java code that builds this panel. So now I see the text on the panel on my screen and I can access the Graphics object that holds that text. I know it was added with drawString(). But if I want to extract that text now, how can I do it? It seems as though it should be easy but there's no getText() method or anything with the Graphics class.
Thanks for any help.
Paul
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

There's really no way to get the text once it's been written to the graphics context. You'll have to find some other way to get the String information you need... are the strings static? (i.e. you know what they're all going to be beforehand. ) If so you might be able to just use a HashMap or something to associate all the images with certain strings...

-nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Borty Gibbon
Greenhorn

Joined: Oct 26, 2001
Posts: 2
What JDK are you using?
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
Version 1.3
 
Don't get me started about those stupid light bulbs.
 
subject: Graphics
 
Similar Threads
Problem on drawing on panel
Translation of 2d objects
To make JLabel move
How to catch number errors?
\n with drawString()