File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes jButton fill colour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jButton fill colour" Watch "jButton fill colour" New topic
Author

jButton fill colour

Tahir Sharif
Greenhorn

Joined: Sep 01, 2009
Posts: 5
How do I change the background colour of a jButton in Netbeans, I'd like to keep the gradient effect.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
Welcome to JavaRanch

Probably better to move this thread to the Swing forum.
Tahir Sharif
Greenhorn

Joined: Sep 01, 2009
Posts: 5
Thanks Campbell
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
You appear not to have any replies yet. Since a JButton is a JComponent and a Component, try changing the background, and applying gradients the same way you would for anything else.
Tahir Sharif
Greenhorn

Joined: Sep 01, 2009
Posts: 5
Thanks, will try that.
Tahir Sharif
Greenhorn

Joined: Sep 01, 2009
Posts: 5
OK, so why didn't I see a "background" in properties before? doh. I've never applied a gradient to anything, and it's not jumping out at me in the properties dialogue, am I looking in the right place?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

Dont know about Netbeans. I always hand code.

What you need to use is the Graphics2D#setPaint() and GradientPaint


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Tahir Sharif
Greenhorn

Joined: Sep 01, 2009
Posts: 5
Thanks, I'll look them up.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
What Maneesh suggests is probably called in the paintComponent() method. You will probably find something useful in the Java™ Tutorials.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jButton fill colour