This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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: 38519
    
  23
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: 38519
    
  23
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: 10270
    
    8

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: 38519
    
  23
What Maneesh suggests is probably called in the paintComponent() method. You will probably find something useful in the Java™ Tutorials.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: jButton fill colour