Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:11:09+00:00 2026-06-14T00:11:09+00:00

I have a composite tree. I’ve drawn this tree to a JPanel width Graphics

  • 0

I have a composite tree. I’ve drawn this tree to a JPanel width Graphics object via overriding paintComponent(Graphics gr). My problem is: how can I access which component is clicked?

I only figured out trivial and bad solutions, so that’s why I turn to you. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:11:10+00:00Added an answer on June 14, 2026 at 12:11 am

    The shapes you have drawn, you need to store.
    When you receive a Mouse clicked event:

    public void mouseClicked(MouseEvent e) {
    

    you will have x and y from

        e.getPoint().getX()
        e.getPoint().getY()
    

    You can then traverse your shapes, and see if a Shape contains the point above. From the Javadoc of Shape:

    /**
     * Tests if the specified coordinates are inside the boundary of the
     * <code>Shape</code>, as described by the
     * <a href="{@docRoot}/java/awt/Shape.html#def_insideness">
     * definition of insideness</a>.
     * @param x the specified X coordinate to be tested
     * @param y the specified Y coordinate to be tested
     * @return <code>true</code> if the specified coordinates are inside
     *         the <code>Shape</code> boundary; <code>false</code>
     *         otherwise.
     * @since 1.2
     */
    public boolean contains(double x, double y);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a business object project, which contains composite structure: public class Tree {
Propose to consider the following problem. Suppose we have some composite object. Are there
I have a composite primary key for my object.How can i use a jpa
We have a composite primary key for the site table defined below. Functionally, this
I have a composite control which emits HTML that looks like this <span id=myControl>
I am trying to build a navigation tree via recursion in JSF. I have
i have a composite component that contains a form with ajax. what i can't
i have composite object Composite composite = new Composite(shell, SWT.NONE); composite.setBounds(new Rectangle(10,10,100,100); How do
I have a composite control that is includes a groupbox control. The problem is
How do you use the tryGetEntity method when you have composite keys? Can it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.