Forums Register Login

Supporting background images in buttons

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 895 times.
Similar Threads
onmouseover event
multiple images using css
How to get target=_blank to work on only 1 of several inputs
Supporting background images in JButton .. I need help here
How to Write Text over an existing image
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:16:43.