• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image as a button

 
kenji jonathan
Greenhorn
Posts: 4
Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make an image that can act like a button in java application.

I have written :



but the result is there is an image inside a button. It isn't what I want to do, I want to make an image that acts like a button...Any suggestion?...Thanks for sharing knowledge..^^
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a JLabel instead of a JButton, and use a mouse listener. You can also change the cursor of the label if you want to.

I'll move this thread to our GUI forum.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Or you can also
1) With your existing code, make your button transparent by using JButton#setContentAreaFilled(false)
2) Refer to http://www.coderanch.com/t/506289/GUI/java/custom-shaped-gui-components and http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/

 
Minh Nam
Ranch Hand
Posts: 57
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kenji jonathan wrote:I want to make an image that can act like a button in java application.

I have written :



but the result is there is an image inside a button. It isn't what I want to do, I want to make an image that acts like a button...Any suggestion?...Thanks for sharing knowledge..^^


This is what I wrote to make a transparent button having only the icon:

 
kenji jonathan
Greenhorn
Posts: 4
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow..thanks for sharing...by the way, now I want to place the button at the center of the window. Is there any simple way to do it?....
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kenji jonathan wrote:I want to place the button at the center of the window. Is there any simple way to do it?....


If the button is the only component in its Container, set a GridBagLayout and add the button without a GridBagConstraints.
 
Rob Camick
Ranch Hand
Posts: 2536
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic