Solved

How to get "Graphics2D" object from a component?

Posted on 2001-06-20
4
766 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
  • 2
4 Comments
 
LVL 2

Expert Comment

by:venkat2000120699
Comment Utility
Just use type casting;

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

This will work...
0
 

Accepted Solution

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

Expert Comment

by:venkat2000120699
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 68
firstChar challenge 13 83
create a gui in perl 3 42
Where to store the queries for modification of table 4 25
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now