• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jButton fill colour

 
Tahir Sharif
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I change the background colour of a jButton in Netbeans, I'd like to keep the gradient effect.

 
Campbell Ritchie
Sheriff
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Probably better to move this thread to the Swing forum.
 
Tahir Sharif
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell
 
Campbell Ritchie
Sheriff
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, will try that.
 
Tahir Sharif
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont know about Netbeans. I always hand code.

What you need to use is the Graphics2D#setPaint() and GradientPaint
 
Tahir Sharif
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'll look them up.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Maneesh suggests is probably called in the paintComponent() method. You will probably find something useful in the Java™ Tutorials.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic