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 8293 articles. 15 followers. Post

9 Replies
354 Views

Similar Articles

[PageSpeed] 31


  • 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...

WHAT vs HOW vs WHERE
In the ongoing discussion here about alternatives to the RM, the subject of pointers keeps coming up. AFAIK, one of the features of the RM is that the interconnectedness of data is established by common data values, instead of pointers. In my view, pointers are "good things" not "bad things". But there are plenty of "good things" that will harm you if you don't use them right. One of the ways a network or graph data base achieves performance is by the efficient use of pointers, and the strategic preplacement of pointers where they will be need...

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...

ex vs. em vs. px vs. % vs. in.
Hello All, I am looking for a for a good tutorial on font size definitions in a CSS. A URL to a good tutorial with demo/example will help. I am trying to create a CSS for DocBook XML Document, but I m unable to get a cross browser/platform compatibility. I want the documents to look fairly similar on all platforms/browsers. Here is my CSS -> http://www.xml-dev.com/blog/new.css And here are 2 plaint text documents using that CSS: http://tinyurl.com/yu3j8 http://tinyurl.com/2zwoh More documents here -> http://www.xml-dev.com/blog/#88 I was told that I should always use...

JSP vs. Struts vs. JSF vs. Swing vs. Tapestry vs. Spring vs. Rails
I am a JSP developer and am constantly feeling like I am missing the boat by not using any of the other frameworks out there. However, the couple I have looked at (JSF and Rails) don't impress me. In JSP, I keep all of my logic in Servlets/Beans and all of my presentation in the JSP file, making custom tags when I need to do some HTML that involves some logic. So Servlets and Tags are the glue to the JSPs and Beans. I don't see what is wrong with this model. The biggest advantage is its flexible. An example of my frustation with JSF (which is different than all the other complaints...

[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...

Magic vs MiNT vs Gevena vs TOS vs...
Hi all, I'm starting this thread for 2 reasons: a) I'm a bit tired of reading the same subject again and again and decided to give it a little twist, b) Personal need. So, without any further ado, my situation is this: I have a stock STE with 4 Megs of memory, in which I'll be adding a hard drive (and maybe more) in this week. Being a floppy user (Atari-wise) all these years I never thought of having any other OSes than plain old TOS, but now, since I'll be getting some more space, I thought I might as well throw in a desktop/accs/resident progs setup there as well...

PowerPC vs. TI DSP vs. IA32 vs. MIPS vs. H8 ...
Hi All, I need to select a platform for a control project. I need suggestions from your guys. Here is the some requirements for the project: 1) Programming in c 2) Two channels of AD > 12bit 3) Two or more quadrature decoders (single ended) 4) > 1 channel of PWM output 5) floating point performance ~ 500MHZ P3 6) Small, reliable and takes only 12V power supply 7) ~32MB DRAM (I really don't know how much my program will require, how to estimate this?) 8) ~32MB FLASH prefer also a VGA display for a color flat panel display. Multimedia Card (or compact flash) interface. Thanks in ad...

fastcgi vs mod perl vs apache vs lighttpd vs perlbal
what is fastest combo folks? >>>>> "g" == gavino <gavcomedy@gmail.com> writes: g> what is fastest combo folks? (no doubt referring to this:) Subject: Re: fastcgi vs mod perl vs apache vs lighttpd vs perlbal It depends on your configuration and what you're doing. Performance for all of them is configuration-dependent: an installation of any of them, tuned to suit your application's specific performance needs, them will most likely perform better an untuned installation of any of the others. (Did you finally get tired of trolling comp.lang...

vi vs. vim vs. emacs vs. ????
I've decided to step back from the IDE and start learning/re-learning Java without the aid of Eclipse or Netbeans. I want to learn about packages and such without having an IDE do all the work for me. So my question is, what's the best editor on a *nix platform? I am somewhat familiar with vi and emacs so I'm trying vim out as my Java editor. Are the others that are better or is a vi* editor a good choice. Not flame bait..just looking for some honest opinions. On Jun 16, 10:54 am, JT <jtlinux1@yaho#Akd9i30.ca> wrote: > I've decided to step back from the IDE a...

Comparisons of TeX vs Groff vs SGML vs DocBook vs TeXinfo
Well, I've had fun with Tex and LaTeX for a while now, but I'd like to know how well the alternatives work, and weather or not I should use these alternatives that are listed usually with TeX. What are your opinions on them, and surely, some must do a job better than the rest (Something must do pictures and tables better) and I probably will use the best one for the specific jobs that may come up in the future. Basically, I'm just asking for a list of strengths and weaknesses that each of these typesetters or document language things have. Thanks Percival Percival Tiglao wrote:...

Qedit vs CodeWright vs Whisper vs ?
I've been a fond fan of Qedit(host) for many years now; already knowing this editor leads me to stay with it when looking for a good client/server editor. But I admit I've also had my head in the sand for years, happily grinding away at my Cobol/Image code, getting real work done, going home tired. Meanwhile, the world's grown up without me. Would you fine folks be so kind as to share your experiences with C/S editors? I know I'll still be working on good old HP3000 Cobol, but now I'm getting into the Unix world, and will probably appreciate having something l...

comparision Jini vs CORBA vs .NET remoting vs. DCOM vs. web services vs. Java RMI
Hi, Would it be fair to compare the following technologies to each other: Jini vs CORBA vs .NET remoting vs. DCOM vs. web services vs. Java RMI? Thanks, Derek On 4 Nov 2005 20:53:09 -0800, "derek" <derek_t_9953@yahoo.com> wrote, quoted or indirectly quoted someone who said : >Would it be fair to compare the following technologies to each other: > >Jini vs CORBA vs .NET remoting vs. DCOM vs. web services vs. Java RMI? > You can compare them. They each have their niche so they are not direct competitors.. CORBA's forte is interlanguage communication -- ty...

Websh vs Rivet vs AOLServer vs PHP
Until now, I've always used PHP for web development. I would like to try Tcl out, but there are so many options. I read that Websh works in Apache 1.3 and 2.0, but Rivet (according to http://tcl.apache.org/) only works with Apache 1.3. As far as I can understand, these both implement different APIs. Then there's AOLServer, which implements yet a third API. What are the relative merits of each of these packages? Specifically, are any of them particularly light-weight? As in lighter than PHP? More importantly, are any of these packages likely to be updated much? It seems li...

Asus vs Toshiba vs IBM vs MSI
Hi I'm looking to possibly buy a laptop around August this year. How would Asus, Toshiba, IBM and MSI compare with reliability, warranty and customer service/technical support? I've read about Toshiba and IBM changing ownership of parts of their companies. How has this affected things? I'd also appreciate any recomendations for other brands for Windows laptops. I'm also thinking of dual booting with Linux (probably Ubuntu) I'm a part time IT student and I'm trying to start up a business using php and Java so I'm looking for a good brand. I'm in Melbourn...

ASSOC vs SHMMAP vs POINT_LUNs vs READ_BINARY?
I have a large multidimensional array. I want to sort it, without doubling the memory requirement by making a same-size array and copying data over, sections at a time. I hear about: - ASSOC? But the raw data is not in large consecutive chunks. Does this preclude its use? - SHMMAP? Seems very low-level and risky without experience. - READU and lots of POINT_LUNs? Would this execute slowly? - READ_BINARY with the TEMPLATE keyword? I should like to hard-code the template rather than use the BINARY_TEMPLATE GUI. I suppose this is possible? I am guessing that READ_BINARY with TE...

ScreamerNet vs. TequilaScream vs. Amleto vs. Spider?
I would like opinions from those who have used third-party Windows network rendering packages for Lightwave (versus the supplied ScreamerNet). Specifically, I'm looking for the pros and cons of using TequilaScream, Amleto, Spider, etc. Best Regards, Washington Bob "Washington Bob" <washington_bob@hotmail.com> wrote in message news:5403d5d.0401161757.18a6648b@posting.google.com... > I would like opinions from those who have used third-party Windows > network rendering packages for Lightwave (versus the supplied > ScreamerNet). > > Specifically, I'm loo...

ATI vs Sapphire vs PowerColor vs etc
Hi there, I've been out of the computer market for awhile now. What's with all these other companies carrying ATI products. For example, I can get a Sapphire Radeon 9600 or a PowerColor 9600 and ATI still has their own 9600. I am seeing these supposedly same products at different prices. What is the difference between the companies and which one would you recommend I get? I am not a gamer. I may do some light video editing though. Thanks for the help. Kindly appreciated. "Kevin" <kevin_uoft@hotmail.com> wrote in message news:5a7a1cbd.0410201540.29397c48@posting.goog...

Perl vs Python vs Ruby.... vs Tcl?
Hello. I found this page interesting http://mjtsai.com/blog/2002/11/25/perl_vs_python_vs_ruby/ Would someone care to show me how this would be done in Tcl please? Thanks. fro...@gmail.com wrote: > Hello. I found this page interesting > > http://mjtsai.com/blog/2002/11/25/perl_vs_python_vs_ruby/ > > Would someone care to show me how this would be done in Tcl please? > Thanks. Probably by using the tcllib csv module and adding some lsearch/lsort - index trickery for Tcl 8.5 or simple iteration with foreach. Michael On 11 sep, 16:31, schl...@uni-oldenburg.de wrote: >...

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...

graphic inside a graphic
Hi everyone Does anybody know how to insert a graphic inside a graphic?? I mean, to add a small graphic (as a zoom for example) inside a plot. Thanks augusto try axes try axes check out the tool 'imshow()', then try to bring the figure in shape get(gca) and superimpose your graph - 'hold on', 'plot()', 'hold off' (Haven't tried it my self so far) Thorben The example below shows you how to insert a graphic (e.g. photo) into another MATLAB figure. I = imread('peppers.png'); theta = linspace(-pi,pi,200); figure; plot(theta,cos(theta)); gr...