• Post Reply Bookmark Topic Watch Topic
  • New Topic

How change background of JPanel?  RSS feed

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want my panel to have a gradient background. I'm using myJPanel.getGraphics() and then using g.setPaint() among other methods. Yet it never changes the JPanel. Does anyone know what I'm doing wrong?
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checkout over riding the panel's paintComponent method - good luck!
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if your JPanel is named jp... then go like this:

where 0xffffff is your color in hex.. in this case, bgcolor is white.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!