Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Mouse listening in JPanel

Posted on 1999-07-27
Medium Priority
Last Modified: 2013-11-23
Hi Experts,

I am using JPanel in JFrame. I added MouseListener, MouseMotionListener to JPanel. Now when i click on the JPanel, mousePressed event is executing. Then i added three JEditorPanes, in the JPanel. When i click on the JEditorPane, in the JPanel my mouseListener is not getting executed. Why this behavi3F. I created one more class that extends JEditorPane and added MouseListener to it. I added this derived class to JPanel, then also the same behaviour. What is the problem?. Please help me

Thanks in Advance
Regards Jagannadh

S/W JDK 1.2.1
O/s 95/NT

Question by:JSarma
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1247193
I think that events are only delivered to the component that is the direct recipient of the event and not to that component's container. Therefore, your JPanel receives MousePressed events when the mouse is pressed over the JPanel directly, but not when the mouse is pressed over a JEditorPane which is inside the JPanel.

To fix this, you need to have call addMouseListener on each of your JEditorPanes with the same MouseListener that you added to your JPanel.  This should cause the MouseEvents to occur as you expect.

Accepted Solution

tny earned 400 total points
ID: 1247194
try this
MyJEditorPane extends JEditorPane
protected void processEvent(AWTEvent e)
      if(e instanceof MouseEvent)


Expert Comment

ID: 6830740
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.
Thank you,
Moderator @ Experts Exchange

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question