Solved

How to get "Graphics2D" object from a component?

Posted on 2001-06-20
4
780 Views
Last Modified: 2011-08-18
 As you know, the "getGraphics()" method of a component
returns a "Graphics" object, but in many cases we need to
pass a "Graphics2D" object for "UI" processes.What is the
solution to this?
  I would be very gratefull if you send me a reply.
Thanks in Advance.
0
Comment
Question by:Mohamadi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:venkat2000120699
ID: 6212793
Just use type casting;

Graphics g = comp.getGraphics();
Graphics2D g2d = (Graphics2D) g;

This will work...
0
 

Accepted Solution

by:
raga earned 50 total points
ID: 6213502
get the graphics objects(say graphics).
cast it to graphics2D objects, i.e.,
Graphics2D graphics2d = (Graphics2D) graphics;
0
 
LVL 2

Expert Comment

by:venkat2000120699
ID: 6215165
Hi raga,

How come your answer is different than that of mine?
Please look at the posted comments, before proposing an answer.... :-)  Hope u will not repeat it again....
0
 

Author Comment

by:Mohamadi
ID: 6216655
Tank you for your kindness.
When I cast the object the "getFontRenderContex()" method
returns "null" value.
Is it because of casting?
Thanks in advance.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question