wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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.
subject: Using GradientPaint and Swing Components
Similar Threads
Understanding abstract methods
JPanel only displays one component
Matisse designer_problem with displaying drawn circle at JPanel/also animation problem
How To Refresh a JDialog?
Focus on JPanel field inside a Confirm Dialog