What is the difference between getGraphics() and getComponentGraphics(Graphics g). I suppose then the question really is what is the, "original," graphics object?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
What is the difference between getGraphics() and getComponentGraphics(Graphics g). I suppose then the question really is what is the, "original," graphics object?
Provide an API reference for getComponentGraphics(Graphics g).
KAJLogic (October 21st, 2013)
Apologies I have work and school to juggle so it may take some time for my reply thanks for waiting.
getGraphics()
Returns this component's graphics context, which lets you draw on a component. Use this method to get a Graphics object and then invoke operations on that object to draw on the component.
getComponentGraphics()
Returns the graphics object used to paint this component. If DebugGraphics is turned on we create a new DebugGraphics object if necessary. Otherwise we just configure the specified graphics object's foreground and font.
No worries.
You went above and beyond with the last post. I was just looking for a link to getComponentGraphics() API, because I couldn't find it. I was having a bad day, I guess, because there it is right on the JComponent page where it should have been. The reason I asked for the link was to gather the specifics of the two calls that you didn't include originally or even in your latest post.
For example, notice both return a Graphics object; that getGraphics() doesn't accept a parameter, so it's use would be:
Graphics g2 = component.getGraphics();
and that getComponentGraphics( Graphics g ) DOES accept a parameter.
From there, it seems they're essentially the same, EXCEPT when the debug graphics options are set, the getComponentGraphics() method returns a DebugGraphics object instead of a normal Graphics object. I've never used a DebugGraphics object, so I'm not sure what you'd do with one if you had it. In "Java Swing" (Loy, et. al.) it says that when the DebugGraphics object is used, drawing is slowed or logged to help the user identify problems. I'll have to try that someday.
Thanks for asking.
KAJLogic (October 21st, 2013)
This clears it up perfectly. I will try to improve my posting etiquette.
While we should all strive to do better at all we do, I don't think you did anything wrong. Forgive me if I gave that impression.