Results 1 to 3 of 3

Thread: Clickable image

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

    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
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    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,

    Build a wall around Donald Trump; I'll pay for it.

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

    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')

    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, 08:59 PM
  2. Clickable text in a component
    By kjkrum in forum AWT / Swing
    Replies: 3
    Last Post: 11-05-2011, 11:25 PM
  3. Make a clickable moving image?
    By scheffetz in forum New To Java
    Replies: 1
    Last Post: 04-08-2011, 07:54 PM
  4. Double Clickable Application
    By ellias2007 in forum Advanced Java
    Replies: 7
    Last Post: 03-08-2010, 04:08 PM
  5. Putting clickable icons on an image
    By szakee in forum AWT / Swing
    Replies: 3
    Last Post: 04-06-2009, 10: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