jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes How to Make Fancy Buttons? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Make Fancy Buttons?" Watch "How to Make Fancy Buttons?" New topic

How to Make Fancy Buttons?

Avin Sinanan
Ranch Hand

Joined: Nov 07, 2001
Posts: 109
Ok let me first state that I can make buttons with pictures in them..The button that i make usually is rectangular or square and within it contains the picture. My question is the following .. thanks in advance :
I want to make a button that takes the shape of my gif picture.
For example if my picture is the Nike logo i want my button to be shaped like the Nike logo. I do not want my button to be rectangular and contain the nike logo.. The button itself must be shaped exactly like the Nike logo.
Example : the following line of code will NOT work :
button= new JButton("", new ImageIcon("nike.gif"));
because this just creates a buttons enclosing the nike picture.. and the button is still rectangular. I want to make it look like the nike pictue.
And I also want to position this button at (50, 60)
Thanks again

yours respectfully<br />Avin Sinanan
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

This question should really go in the SWING/JFC Forum, but until someone moves it, I will start to answer your question.
I'm sure that if you override the paint method by extending JButton/Button you could change the shape of your Button. However, there is no way to make a Button just "take the shape of" your Gif Image.
So here is what I would suggest....
First, try and make the Button as small as you can while still fitting the GIF image on it. Then, Button.setBorderPainted(false). That will remove the raised border from the button, so now it will appear that you just have a GIF image on the screen. Next, it would be a good idea to create two GIF images of your NIKE logo. Possibly make one look raised above the other. Then you can set either a pressedIcon and/or a mouseoever Icon that changes the NIKE logo to make it appear that it is actually the Button.
These methods are fairly simple and really look nice if you take some time with your GIF Images.
Hope that helps.
Happy Coding,
Gregg Bolinger

GenRocket - Experts at Building Test Data
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2591

Maybe just use a subclass of Canvas and handle required event of the class. That would make your Nike swoosh look like a swoosh.
- Manish
I agree. Here's the link: http://aspose.com/file-tools
subject: How to Make Fancy Buttons?
jQuery in Action, 3rd edition