• Post Reply Bookmark Topic Watch Topic
  • New Topic

Supporting background images in buttons

 
Meghna ks
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I've designed a ToolBar bean which has a series of buttons. I need the buttons to support background images apart from the text & icon that come as part of the button constructor. How do I approach this problem ?!! Is it possible to support background images using JButton ?!!
Thanks
Meghna
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not directly... no... but it has to be possible to 'roll your own'... I suspect you may have to extend ButtonUI and then do a setUI() on the JButton with your new UI... I tried to give you a quick fix, but unfortunatly I don't understand Swing as much as AWT...

I tried to make a simple component that extended JButton, only you could add a background image to it... it worked pretty well... except it looked like a normal JButton! So I removed the call to super.paint(), got the text and icon off the JButton and painted them on top of the background image... this looked OK until the mouse moved over the buttons! Graphic artifacts all over the place! I think my problem was that I was going about things in a more 'AWT way' than a 'Swing way'... I think the Swing way would be to make a new ButtonUI class that supports background images... unfortunately, I don't know enough about Swing to help you out on this...

Hopefully, my mistakes and suggestions will guide you to a way to solve this...

-Nate
 
Meghna ks
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nathan
Thanks a lot for trying to give me a solution, altho' its a bit unfortunate that I could'nt find it in swing. But, I do appreciate your participation.
If anybody else has any solutions for my problem, please fill me in immediately. Its a major requirement.
Thanks again !!
Meghna
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!