Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Clicking the image like a button

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Clicking the image like a button

    how can I click an image like a button..

    so instead of using the JButton I am using an Image


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Clicking the image like a button

    Use the setIcon method of JButton to set the image. You can also use the setPressedIcon to have the icon change when the JButton is pressed. I recommend reading the Swing tutorial provided by Oracle for more information:
    How to Use Buttons, Check Boxes, and Radio Buttons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    Alternatively you could draw your image on a JComponent and add a MouseListener to manage clicks.

Similar Threads

  1. Im trying to open a new GUI window by clicking on a button
    By amzwans in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 10th, 2011, 11:33 PM
  2. Replies: 3
    Last Post: February 21st, 2011, 07:25 PM
  3. How to display a button with an image on it?
    By ice in forum AWT / Java Swing
    Replies: 10
    Last Post: November 13th, 2010, 06:20 AM
  4. unable to go to next page...while clicking submit button
    By javaking in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: April 29th, 2010, 02:55 AM
  5. How to upload a file by clicking a link instead of button?
    By raghuprasad in forum Java Theory & Questions
    Replies: 2
    Last Post: May 3rd, 2009, 05:21 AM