Mouse listening in JPanel

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

Who is Participating?
tnyConnect With a Mentor Commented:
try this
MyJEditorPane extends JEditorPane
protected void processEvent(AWTEvent e)
      if(e instanceof MouseEvent)

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.
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.