Graphics vs. Graphics2D

  • Permalink
  • submit to reddit
  • Email
  • Follow


I'm working on drawing a gradient.  The Java Developers Almanac just
casts paint()'s Graphics parameter to Graphics2D.

http://javaalmanac.com/egs/java.awt/color_SetGradient.html

How reliable is this?  Will a JPanel's paint (Graphics) method always
be passed a Graphics2D?  A JPanel is 2D, so I guess that would make
sense ...

Any thoughts appreciated.

-- 
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
0
Reply Monique 3/16/2006 5:29:31 PM

See related articles to this posting


In article <slrne1j83r.it3.spam@home.bounceswoosh.org>,
 "Monique Y. Mudama" <spam@bounceswoosh.org> wrote:

> I'm working on drawing a gradient.  The Java Developers Almanac just
> casts paint()'s Graphics parameter to Graphics2D.
> 
> http://javaalmanac.com/egs/java.awt/color_SetGradient.html
> 
> How reliable is this?  Will a JPanel's paint (Graphics) method always
> be passed a Graphics2D?  A JPanel is 2D, so I guess that would make
> sense ...
> 
> Any thoughts appreciated.

In the Javadocs for Graphics2D, it says that it's the "fundamental class 
for rendering 2-dimensional shapes, text and images" and therefore leads 
me to believe it's reliable.  That article, however, seems to suggest 
overriding the paint method, which is generally not advisable in Swing.  
You should normally override the paintComponent method instead.

= Steve =
-- 
Steve W. Jackson
Montgomery, Alabama
0
Reply Steve 3/16/2006 6:28:16 PM

"Monique Y. Mudama" <spam@bounceswoosh.org> wrote in message 
news:slrne1j83r.it3.spam@home.bounceswoosh.org...
> I'm working on drawing a gradient.  The Java Developers Almanac just
> casts paint()'s Graphics parameter to Graphics2D.
>
> http://javaalmanac.com/egs/java.awt/color_SetGradient.html
>
> How reliable is this?  Will a JPanel's paint (Graphics) method always
> be passed a Graphics2D?  A JPanel is 2D, so I guess that would make
> sense ...
>
> Any thoughts appreciated.

The class hierarchy seems to be as follows:

java.awt.Graphics (abstract)
|- javax.swing.DebugGraphics
|- java.awt.Graphics2D (abstract)
|  |- sun.print.PeekGraphics
|  |- sun.print.ProxyGraphics2D
|  |  `- sun.print.PathGraphics (abstract)
|  |     |- sun.print.PSPathGraphics
|  |     `- sun.awt.windows.WPAthGraphics
|  `- sun.java2d.SunGraphics2D (final)
|- sun.print.ProxyGraphics
|  `- sun.print.ProxyPrintGraphics
`- javax.swing.SystemEventQueueUtilities.RunnableCanvasGraphics (static 
private inner)

    DebugGraphics seem to only come up if you turn on debuging for your 
component via the setDebugGraphicsOptions() method.

    I couldn't find sun.print.ProxyGraphics being used anywhere, and given 
the package name, it's probably for "internal use only".

    RunnableCanvasGraphics has something to do with an optimization for 
applets for situations where it is known before hand that no painting will 
be done, so you should never actually see an instance of this.

    So basically, the only situation you have to worry about is 
DebugGraphics. As long as you never touch the setDebugGraphicsOptions() 
method (and I've never seen a Java program actually use that method), you 
should be okay.

    - Oliver 

0
Reply Oliver 3/16/2006 6:30:21 PM

Monique Y. Mudama wrote:
> I'm working on drawing a gradient.  The Java Developers Almanac just
> casts paint()'s Graphics parameter to Graphics2D.
> 
> http://javaalmanac.com/egs/java.awt/color_SetGradient.html
> 
> How reliable is this?  Will a JPanel's paint (Graphics) method always
> be passed a Graphics2D?  A JPanel is 2D, so I guess that would make
> sense ...
> 
> Any thoughts appreciated.
> 

The Graphics object in a JPanel is always a Graphics2D.  I think but 
can't find it in the docs that all Swing components are the same.

-- 

Knute Johnson
email s/nospam/knute/
0
Reply Knute 3/16/2006 6:47:34 PM

On 2006-03-16, Steve W. Jackson penned:
> In article <slrne1j83r.it3.spam@home.bounceswoosh.org>, "Monique Y.
> Mudama" <spam@bounceswoosh.org> wrote:
>
>> I'm working on drawing a gradient.  The Java Developers Almanac
>> just casts paint()'s Graphics parameter to Graphics2D.
>> 
>> http://javaalmanac.com/egs/java.awt/color_SetGradient.html
>> 
>> How reliable is this?  Will a JPanel's paint (Graphics) method
>> always be passed a Graphics2D?  A JPanel is 2D, so I guess that
>> would make sense ...
>> 
>> Any thoughts appreciated.
>
> In the Javadocs for Graphics2D, it says that it's the "fundamental
> class for rendering 2-dimensional shapes, text and images" and
> therefore leads me to believe it's reliable.  That article, however,
> seems to suggest overriding the paint method, which is generally not
> advisable in Swing.  You should normally override the paintComponent
> method instead.
>

Thanks for the info.  The connection to JPanel was mine; the article
is in the AWT section of the Almanac.  I don't think the article ever
implies you should use it for Swing; rather it just doesn't explicitly
state it's talking about AWT.

-- 
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
0
Reply Monique 3/16/2006 6:52:49 PM

On 2006-03-16, Oliver Wong penned:
>
>     So basically, the only situation you have to worry about is 
> DebugGraphics. As long as you never touch the setDebugGraphicsOptions() 
> method (and I've never seen a Java program actually use that method), you 
> should be okay.
>

Thanks so much.  I hate just flat-out assuming it will always be a
Graphics2D object, but it sounds like I can.  I'll just add a test so
that, if it's ever not a Graphics2D, it will at least draw a single
color.

-- 
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
0
Reply Monique 3/16/2006 7:14:54 PM

Oliver Wong wrote:
> 
>    So basically, the only situation you have to worry about is 
> DebugGraphics. As long as you never touch the setDebugGraphicsOptions() 
> method (and I've never seen a Java program actually use that method), 
> you should be okay.

There's an RFE for DebugGraphics to support Graphics2D. Opened 1999. 
Evaluated as a good idea 2001. 3 votes. You know where the jdk 
collaboration site is if you want something done about it.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4262543
https://jdk-collaboration.dev.java.net/

IIRC, some of the PL&Fs cast to Graphics2D without checking, but not 
consistently.

Tom Hawtin
-- 
Unemployed English Java programmer
http://jroller.com/page/tackline/
0
Reply Thomas 3/16/2006 7:28:14 PM

"Thomas Hawtin" <usenet@tackline.plus.com> wrote in message 
news:4419bc11$0$9271$ed2619ec@ptn-nntp-reader01.plus.net...
> Oliver Wong wrote:
>>
>>    So basically, the only situation you have to worry about is 
>> DebugGraphics. As long as you never touch the setDebugGraphicsOptions() 
>> method (and I've never seen a Java program actually use that method), you 
>> should be okay.
>
> There's an RFE for DebugGraphics to support Graphics2D. Opened 1999. 
> Evaluated as a good idea 2001. 3 votes. You know where the jdk 
> collaboration site is if you want something done about it.
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4262543
> https://jdk-collaboration.dev.java.net/
>
> IIRC, some of the PL&Fs cast to Graphics2D without checking, but not 
> consistently.

    Thanks for the heads up. I added a vote.

    - Oliver 

0
Reply Oliver 3/16/2006 8:04:34 PM

Monique Y. Mudama wrote:
> I'm working on drawing a gradient.  The Java Developers Almanac just
> casts paint()'s Graphics parameter to Graphics2D.
> 
> http://javaalmanac.com/egs/java.awt/color_SetGradient.html
> 
> How reliable is this? 

Deep down somewhere in some Java documentation (AFAIR it was some 
JDK/JRE release notes), Sun "guaranteed" that with the introduction of 
Java 2D one gets a Graphics2D instead of a Graphics object.

Of course, they screwed it up :-(. At the same time they added 
paintComponent(Graphics). It would have been easy to make that a 
paintComponent(Graphics2D) in Swing, and also add a 
paintComponent(Graphics2D) to AWT.

/Thomas
-- 
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
0
Reply Thomas 3/17/2006 7:59:10 AM

Thomas Weidenfeller wrote:
> 
> Of course, they screwed it up :-(. At the same time they added 
> paintComponent(Graphics). It would have been easy to make that a 
> paintComponent(Graphics2D) in Swing, and also add a 
> paintComponent(Graphics2D) to AWT.

IIRC, Graphics2D was added to 1.2, but Swing was available for 1.1. 
OTOH, you could argue that Swing on 1.2 shouldn't have been compatible 
with Swing for 1.1 (indeed beta versions had different package names).

Tom Hawtin
-- 
Unemployed English Java programmer
http://jroller.com/page/tackline/
0
Reply Thomas 3/17/2006 4:31:58 PM
comp.lang.java.gui 8296 articles. 15 followers. Post

9 Replies
280 Views

Similar Articles

[PageSpeed] 11


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Epson MX-80 w/ Graftrax vs. FX-80 Graphics (vs. LQ graphics)
Does anyone have a clear memory of the different ways the Epson MX, FX and LQ series utilized graphics? In particular, was the "MX-80 with GRAFTRAX" an option that was designed specifically for the TRS-80? Did the FX offer bit modes that were programmed differently than the MX-80 w/Graftrax? I know the docs are there to be studied but before doing this I am wondering if anyone knows off the top of their heads. Also, do any of the TRS-80 Model 1 or Model 3 drawing programs offer specific support for printing TRS-80 graphics dumps? If so, which programs? (thx) ...

MPC8425 vs Little Endian Graphics Adapter vs WindML vs JWorks
Ok, here's an apparently complicated puzzle that probably has an easy solution. Just I can't see what it is at the moment! Basically, we have an Silicon Motion LynxEM4+ graphics device running in a Motorola Sandpoint X3 development system. The CPU is an MPC8425 (PPC603-based). We have JWorks 4.1, WindML 3.0 and Tornado 2.2. My problem is that, although the SMI graphics device has a big-endian capability, it does not work properly in 16-bit colour depths (it only swaps bytes on 32-bit boundaries it would seem). So it looks like I am going to be forced to use the little endian framebuf...

Wii Madden graphics: ATI vs ATI vs Nvidia
IGN Wii: Let's talk about graphics. Right or wrong, Madden for Wii is undoubtedly going to be compared to the GameCube build. Meanwhile, we've been playing a lot of the 360 version. In terms of visuals, where does the Wii incarnation fit in? Jason Armenise: We get the graphics question all the time. Every time we talk about the game we get the graphics question. A lot of people - even passionate Nintendo fans - are kind of dismissing the graphics, saying, "We know it's going to be third, yadda, yadda, yadda." We didn't take that attitude. Right from the beginning, w...

Wii Madden graphics: ATI vs ATI vs Nvidia
IGN Wii: Let's talk about graphics. Right or wrong, Madden for Wii is undoubtedly going to be compared to the GameCube build. Meanwhile, we've been playing a lot of the 360 version. In terms of visuals, where does the Wii incarnation fit in? Jason Armenise: We get the graphics question all the time. Every time we talk about the game we get the graphics question. A lot of people - even passionate Nintendo fans - are kind of dismissing the graphics, saying, "We know it's going to be third, yadda, yadda, yadda." We didn't take that attitude. Right from the beginning, w...

Driver calls vs graphics mutex vs Ethernet card
I am currently debugging a multithreaded application where one thread (the "Render" thread) is using the display driver (i.e. through ExtEscape calls). The system is a dual CPU Windows 2000 system (SP2), with two displays (i.e. two display drivers); the application is using the secondary display only. The Render thread is running at real-time priority (i.e. priority 29). I have a strange problem where once in a while, an ExtEscape call to the display driver (e.g. some custom escape function) takes _way_ too much time (ex: 12msec). After thorough debugging, I know that my a...

[News] Benchmark: Closed Source Graphics Drivers vs. Open Source Graphics Drivers
X.Org 7.2: ATI Open v. Closed Drivers ,----[ Quote ] | With respect for the differences between the X300 and X800, the | results had not changed much. The ATI/AMD fglrx driver continues to | lead in the frame-rate performance over the open-source Radeon | driver. In Enemy Territory the fglrx driver was over twice as | fast, while in Unreal Tournament 2004 the performance difference | for the fglrx driver spiked at 460% faster. | | While these fglrx drivers are faster for gamers, the open-source | drivers continue to boast the advantages of desktop effects | support (AIGLX), inclusion with a...

PC graphics vs. Xbox360
I know, it is a pc ng. I have a gaming PC and no console. Until recently, I was under the impression that console graphics could never be as good as PC graphics. Well, I saw a few movie from COD2 - Some on the PC and some taken from Xbox 360. The later's graphics seem so much better. Is this true that no current PC can meet Xbox 360 for now or was it simply because of other factors such as resolution, etc.. (the player models were much more detailed on the 360 than on the PC). TIA "Frank" <NOSPAM@NOSPAM.com> wrote in message news:HcOdndNRZ5WQlxfenZ2dnUVZ_sadnZ2...

DVI vs VGS graphics
I recently ordered (and have received) a Dell Inspiron PC. I ordered it with the default Intel integrated (on-motherboard) graphics, because I'm not interested in gaming or cpu-intensive graphics. But I was disappointed when I discovered that it doesn't have a DVI connector...I had read that DVI was invented specifically for LCD displays, to avoid the unnecessary D/A and A/D conversion. (And my display IS a large flat-panel LCD). My monitor was marked as "optimum resolution of 1680x1050". The integrated graphics says "1920x1200" max, so the resolution numbers of ...

Graphics: drawPolygon vs fillPolygon
I've read the documentation, and I'm still having troubleunderstanding exactly why fillPolygon() doesn't (always) produce afilled-in version of drawPolygon(). Specifically, I have thefollowing class:public class UpIcon implements Icon { private final Polygon polygon = new Polygon( new int[]{2,8,5}, new int[]{5,5,2}, 3 ); public void paintIcon( Component c, Graphics g, int x, int y ) { g.drawPolygon( polygon ); // Gives me the shape I want, not filled // in of course. g.fillPolygon( polygon ); // Seems to fill the *interior* of t...

Aperture vs Graphic Converter
Why would I use Aperture over Graphic Converter (except for the raw formats supported)? Seriously - what are the advantages? Thinking of buying it (Aperture) - but then again it ain't free :-) TIA Marc -- Switzerland/Europe <http://www.heusser.com> remove CHEERS and from MERCIAL to get valid e-mail "Marc Heusser" <marc.heusser@CHEERSheusser.comMERCIALSPAMMERS.invalid> wrote in message news:marc.heusser-6D7A4D.00593822102005@news.cybercity.ch... > Why would I use Aperture over Graphic Converter (except for the raw > formats supported)? None. > Serious...

Graphic Converter vs Photoshop
Which one is better? -- Are there errors in the Bible? How should a church conduct its worship services? Is drinking Alcohol a sin? Is racism wrong? If you want to learn, get answers, and be able to defend the faith, CERM is your place. http://www.cerm.info In article <jwolf6589-0E8281.22135230032010@nntp.charter.net>, John <jwolf6589@NOSPAMgmail.com> wrote: > Which one is better? photoshop does *far* more things than graphic converter could ever dream of (and much faster too), but it really depends on what you need to do. converting obscure file formats is b...

Shared vs Dedicated graphics...
What is the difference?? I notice the dell 8600 has a 128MB Video option....is this shared or dedicated? If dedicated, how would the performance differ from the HP and compaq models being offered with 128 shared?? KB wrote: > What is the difference?? > I notice the dell 8600 has a 128MB Video option....is this shared or > dedicated? If dedicated, how would the performance differ from the > HP and compaq models being offered with 128 shared?? First, the amount of shared video RAM is removed from the total available system RAM. If you run at the 128MB shared, a 256MB total RAM...

cgi vs. PC graphics
I just started noticing that now days computer graphics are almost as good, in some cases "better" than CGI in movies and shows now days? I watched "Father of the Pride" a few weeks ago, and the CGI seemed OK to me, but it was nothing that couldn't be done with a PC in realtime now days, I'm sure (and BTW, I still preffer "The Simpsons", both for the visual style, and for the humor/background.) I've been playing more of "The Sims 2", and considering it has relatively low system requirements, the graphics are impressive- they aren't ...

How to draw vector graphics on Graphics2D
Hello, I'm looking for some tips, libraries or tools (it can be commercial solution) to draw a vector graphics on Graphics2D (it can be one of the: EPS, PDF, SVG, WMF, DXF, DWG file) I need to add some scaled images from vector graphics format also some graphics in raster format and show it to user and print. Is there any way that I could do it? Or maybe some ideas? wookashs a �crit : > Hello, > > I'm looking for some tips, libraries or tools (it can be commercial > solution) to draw a vector graphics on Graphics2D (it can be one of > the: EPS, PDF, SVG, WMF, DXF, DWG...

V6 Graphics Vs. MXE
Hello I was wondering what whould be better overall? Should I spend my money on a MXE or V6? of wait even longer and get a higher of the Vx series.... Thank you. boo@hipmediacorp.com bo opfer wrote: > Hello I was wondering what whould be better overall? > > Should I spend my money on a MXE or V6? of wait even longer and get a higher > of the Vx series.... > > Thank you. > boo@hipmediacorp.com > > A little more information from you would help, i.e. - What type of applications are you running? Depending on your applications, you ma...

AGP vs PCI graphics
Building a new PC requires deciding on an AGP or PCI motherboard. Nvidia's Quadro FX adaptors seem to be great performers but is one (AGP) better than the other (PCI)? All responses appreciated. Mike, AGP would be much faster then PCI. Unless you meant ExpressPCI. Then they would be about equal today, but in the future ExpressPCI will have the edge. Paul Mike Pagel wrote: > Building a new PC requires deciding on an AGP or PCI motherboard. > Nvidia's Quadro FX adaptors seem to be great performers but is one (AGP) > better than the other (PCI)? &...

Graphical Model vs Random Graph
Are they the same thing? What's the difference? Thank you! Tim [ comp.ai is moderated ... your article may take a while to appear. ] On Feb 8, 2:02 pm, Tim <liting0...@gmail.com> wrote: > Are they the same thing? What's the difference? > Thank you! > Tim > Hey Tim, I wasn't sure if you were referring to graphical modeling as in radiation modeling (or similar scientific application), or something else. In my personal work I used to create graphical models to predict behavior of given variables implementing Bayesian methods. I'm not too familiar w/ random gra...

graphics cards vs video cards
why are graphics cards way more expensive than video cards, even though they have slower core and memory speeds? I believe "Graphics cards and "video cards" are the same thing. "b" <bruin70@mail.com> wrote in message news:95513a07.0408031434.61c9a9bb@posting.google.com... > why are graphics cards way more expensive than video cards, even > though they have slower core and memory speeds? Huh? Graphics cards = Video Cards. Two different names for the same thing. -- DaveW "b" <bruin70@mail.com> wrote in message news:95513a07.0408031...

graphics library vs Si engine
Hello, can someone point me to references on topics such as : -OpenGL/DirectX vs HW accelerators -pro-and-cons of SW development using these libraries vs silicon development -implementing graphics engine using above libraries vs silicon implementation (performance vs development time), appreciate your comments, Dubi In article <bhs4kp$389$1@news01.intel.com>, DB wrote: > can someone point me to references on topics such as : > -OpenGL/DirectX vs HW accelerators You're asking the wrong question, but the answer is nevertheless: both. You need HW accelerators to have decent p...

3d graphics in Matlab vs OpenGL
All, I'm planning on looking into doing a 3d graphics playback. I was wondering how to best accomplish this. A friend said use openGL. I saw some cool matlab stuff done in the file exchange, and we work with matlab anyways. 1. Can I use matlab to interface with openGL directly? 1a. If not can I use matlab to interface with C/C++ and then use openGL? 2. Would Matlab be able to support a 3d moving objects and such with the same speed/quality as openGL? Thanks Ryan wrote: > All, > > I'm planning on looking into doing a 3d graphics playback. I was > wondering how to be...

Forward vs Redirect of Embedded Graphics
Using 6.1.2.0 paid, I find that, if I try to forward email containing embedded graphics, the graphics generally do NOT forward. However, if I REDIRECT the same email, the graphics are sent perfectly. Obviously, I don't understand why this should be, suggesting that I'm ignorant of how the software functions. Can anyone explain for my education? Thanks. RWE RWEmerson <foolish_consistency@hobgoblin.com> wrote in news:10jh9mnk3o39068 @corp.supernews.com: > Using 6.1.2.0 paid, I find that, if I try to forward email containing > embedded graphics, the graphics...

AGP vs. PCI graphics cards
Hi, I'm researching the purchase of a graphics card for my 2001 G4 "Digital Audio" [1], and I'm not sure whether to replace the built-in one with an AGP card (ATI Radeon 9xxx looks nice), or to add a PCI card and keep the option of adding a second screen without having to buy an ADC->VGA adaptor. I've found a lot on AGP vs. PCI in the Newsgroup's archives, but I'm still not sure how this applies to me. Can anyone here provide a clue? 1) In <http://groups-beta.google.com/group/comp.sys.mac.hardware.video/browse_t hread/thread/5e51176e8...

Mac vs PC Graphics Cards
Hi, I'm in the market for a new graphics card for my old G4 466 (Digital Audio) "Clockwork". I've looked around, and noticed that while most ATI cards seem to come as special "Mac Edition" cards, there seem to be nVidia cards that don't distinguish between Mac and PC cards. Am I mistaken? If not, why is this so? How "portable" are Graphics cards? Any clues would be greatly appreciated. Cheers, -- M. Uli Kusterer http://www.zathras.de In article <witness-B10AA9.16063207022005@news.t-online.com>, Uli Kusterer <witnes...

graphics cards vs video cards
why are graphics cards way more expensive than video cards, even though they have slower core and memory speeds? I believe "Graphics cards and "video cards" are the same thing. "b" <bruin70@mail.com> wrote in message news:95513a07.0408031434.61c9a9bb@posting.google.com... > why are graphics cards way more expensive than video cards, even > though they have slower core and memory speeds? Huh? Graphics cards = Video Cards. Two different names for the same thing. -- DaveW "b" <bruin70@mail.com> wrote in message news:95513a07.0408031...