• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

transparent jbuttons

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it's a lot simpler than that... just call these two methods on your JButton :
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic