Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes Using GradientPaint and Swing Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using GradientPaint and Swing Components" Watch "Using GradientPaint and Swing Components" New topic

Using GradientPaint and Swing Components

John Macek

Joined: Feb 26, 2002
Posts: 2
Is there is any way to use GradientPaint to have my swing components with a gradiated background? I want to have a Jpanel that shades from one color to another from top to bottom. I am using the JPanel in an extension of the JDialog class. I have tried overriding the paint method in my extension of JDialog and calling Graphics2D's setPaint method to use a GradientPaint. I have also tried calling the JPanel's getGraphics method and using setPaint on that. None of this has made any difference. The runtime class of each Graphics is SunGraphics2D. I have been unable to find source code for this class.
Any help would be greatly appreciated.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Here's some example code I made for a JPanel that has a GradientPaint background... Hopefully this helps you out...


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
John Macek

Joined: Feb 26, 2002
Posts: 2
That's pretty much what I did. Thanks.
I agree. Here's the link:
subject: Using GradientPaint and Swing Components
It's not a secret anymore!