This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Make Fancy Buttons?

 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe just use a subclass of Canvas and handle required event of the class. That would make your Nike swoosh look like a swoosh.
HTH,
- Manish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic