This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using GradientPaint and Swing Components" Watch "Using GradientPaint and Swing Components" New topic
Author

Using GradientPaint and Swing Components

John Macek
Greenhorn

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.
Thanks,
John
Nathan Pruett
Bartender

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



-Nate


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

Joined: Feb 26, 2002
Posts: 2
That's pretty much what I did. Thanks.
 
wood burning stoves
 
subject: Using GradientPaint and Swing Components