Results 1 to 3 of 3

Thread: Clickable image

  1. #1
    xtre is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Clickable image

    Hi, I'm trying to get a small image inside of a window which is on top of its background image
    to receive clicks, which would then do something. How should the frame be made so that it works
    and I'm not sure how to get the image to receive the clicks. At the moment I'm using Canvas and JFrame.

    Any help is appreciated. Thanks.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,725
    Blog Entries
    7
    Rep Power
    21

    Default Re: Clickable image

    Use an ordinary JButton, and put the image in as an Icon; don't draw the JButton border, nor its interior (read the JButton API) so that only the image of the JButon is drawn.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Clickable image

    Quote Originally Posted by xtre View Post
    I'm using Canvas and JFrame.
    Quite apart from the approach being suboptimal, don't unnecessarily mix AWT and Swing components in the same GUI. And anywhere it's unavoidable, first research possible anomalous behavior (Hint: search the net for 'mixing heavyweight and lightweight components')

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JButton not clickable
    By StevenTNorris in forum AWT / Swing
    Replies: 5
    Last Post: 11-09-2012, 09:59 PM
  2. Clickable text in a component
    By kjkrum in forum AWT / Swing
    Replies: 3
    Last Post: 11-06-2011, 12:25 AM
  3. Make a clickable moving image?
    By scheffetz in forum New To Java
    Replies: 1
    Last Post: 04-08-2011, 08:54 PM
  4. Double Clickable Application
    By ellias2007 in forum Advanced Java
    Replies: 7
    Last Post: 03-08-2010, 05:08 PM
  5. Putting clickable icons on an image
    By szakee in forum AWT / Swing
    Replies: 3
    Last Post: 04-06-2009, 11:25 AM

Posting Permissions

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