Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JScrollPane does not pass MouseEvents to parent Container

843806Mar 12 2008 — edited Mar 12 2008
I'm having issues with MouseEvents that occur within a JScrollPane. The scrollpane is within another container which has registered mouse listeners. However, these listeners never get called when mouse events occur within the scroll pane. Any ideas what is happening to these events and how to fix this?

Here is some example code that illustrates the problem:
public class Test extends JScrollPane
{
  public Test()
  {
    JPanel canvas = new JPanel();
    canvas.add( new JLabel("Test") );

    setViewportView( canvas );
    setVisible(true);
  }

  public static void main( String[] args )
  {
    JFrame frame = new JFrame();
    frame.setSize( 100, 100 );
    frame.setVisible(true);
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    frame.addMouseListener( new MouseAdapter(){
        public void mouseClicked( MouseEvent e ){
        System.out.println("click!"); } });

    frame.add( new Test() );
  }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2008
Added on Mar 12 2008
5 comments
474 views