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 7 of 7

Thread: How do I select an object in a JFrame using the mouse?

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do I select an object in a JFrame using the mouse?

    I have a JFrame with a JPanel in it. In the JPanel I have a list of objects that consist of panels and JLabels and JFields. I am trying to select one of these nested panels with the mouse. Is there a method of the MouseEvent that let's you figure out which object was clicked on?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do I select an object in a JFrame using the mouse?

    The event object passed to the listener has a method that will return the source of the event.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I select an object in a JFrame using the mouse?

    Any idea what that method is? I tried the .getClass() and all that does is return the java..... whatever the library is.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do I select an object in a JFrame using the mouse?

    You may have to look at the methods for the classes that are extended by the MouseEvent class to see what method gets the source of the event. They are all listed below the doc for the MouseEvent class.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I select an object in a JFrame using the mouse?

    I looked at all the methods that are inherited by the MousEvent in the official documentation.I can't find anything that returns what object was clicked on =(

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do I select an object in a JFrame using the mouse?

    Did you search for the String: "source"?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: How do I select an object in a JFrame using the mouse?

    @nicz17: Care to try for strike three?

Similar Threads

  1. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  2. problem with my JFrame; JFrame not closing and stay in background
    By golominator in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 6th, 2012, 08:20 AM
  3. [SOLVED] Graphics Object Won't Draw To The Correct JFrame
    By NickNumero in forum AWT / Java Swing
    Replies: 7
    Last Post: October 27th, 2012, 01:07 PM
  4. How to display a Rectangle object in JFrame (Problem).
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2012, 07:22 PM
  5. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM