• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Image as a button

 
Greenhorn
Posts: 4
Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..^^
 
Sheriff
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/t/506289/GUI/java/custom-shaped-gui-components and http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/

 
Ranch Hand
Posts: 57
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?....
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic