Solved

How to get "Graphics2D" object from a component?

Posted on 2001-06-20
4
774 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 96
Java Jpanels and Jframe 8 32
Java SE 8u111  Lot of stuff broke 11 69
null output 3 24
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

776 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