• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

transparent jbuttons

 
Jim Henessey
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm working on a calendar app with a background image in a JPanel. I would like to have the borders of the various days painted in with the day in the upper right corner of each day as a jbutton, allowing users to click on it and edit their schedule for that day. Is it possible to have a transparent jbutton - when I try the usual setopaque, I'm told this isn't allowed for this component. Is there an alternative way of creating a transparent jbutton than through this method?
Thanks.
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to create customised Button - a class extending JButton, overriding paint() method. In paint() method, you have to provide painting for the component.
Note: don't call super.paint() in paint() method implementation.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it's a lot simpler than that... just call these two methods on your JButton :
 
Lee Barney
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JLabel would also work if you add a mouseListener. I have done this. I can then controle the size of the component very well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic