Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Norm

Thread: How to use image as button

  1. #1
    mangesh.gho is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default How to use image as button

    I'm trying to design screen as specified. i searched a lot but didn't found proper help.
    I'm beginner in java so please explain me the simplest way. the images used are in .png format & are transparent. i looks very bad when used over jbutton so i want to use those images work as buttons. If not possible, can we have links through those images? how? which way will be simpler? (by clicking these images, i want to open new frames. please tell me how to do that..)
    Thank you.
    How to use image as button-free-wood-texture-002.jpg
    Last edited by mangesh.gho; 01-08-2012 at 09:44 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: How to use image as button

    by clicking these images, i want to
    Look at using Mouse listeners. If you know where your images are, you can map the mouse click's location to an image. You would need to build a list of where the shapes are located that you could search with the mouse click's location.
    quad64bit likes this.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: How to use image as button

    You can add an image to a button. Then you can use:

    button.setBorderPainted(false);
    button.setContentAreaFilled(false);

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: How to use image as button

    Do you want rectangular areas to click on?
    Or do you want to be able to click on the shape of the images?

    Can buttons have non-rectangular areas for clicking?

  5. #5
    mangesh.gho is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: How to use image as button

    Actually it would be better if i could implement button with shape of that image but i don't want to make this thing complicated so if those two methods mentioned above, does the required job then i 'll be fine for me.. Any other suggestions?

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: How to use image as button

    Can buttons have non-rectangular areas for clicking?
    I guess you didn't check out my suggestion in this posting: Custom JButton :-)

    Actually it would be better if i could implement button with shape of that image but i don't want to make this thing complicated
    The easy part is using the button. The hard part is implementing the Shape to use for click detection.

    Any other suggestions?
    Did you actually try using a button? It will be rectangular like the first suggestion unless you override the contains() method as I suggested.

Similar Threads

  1. Hide a button but keep the image?
    By Rtme in forum AWT / Swing
    Replies: 13
    Last Post: 06-05-2011, 05:05 PM
  2. Make a button class that uses your button image.
    By eLancaster in forum New To Java
    Replies: 1
    Last Post: 04-26-2011, 11:32 AM
  3. button displays image
    By hopelessnoob in forum AWT / Swing
    Replies: 2
    Last Post: 03-12-2011, 03:44 PM
  4. AWT button image
    By timkd127 in forum AWT / Swing
    Replies: 2
    Last Post: 03-01-2010, 04:41 AM
  5. Set focus on image button in swt
    By diva_garg in forum New To Java
    Replies: 3
    Last Post: 08-18-2008, 12:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •