problem with mouse listener on GLCanvas/GLJPanel in Netbeans RCP

I have a TopComponent (from Netbeans RCP) with a GLCanvas (tried GLJPanel, too) sitting in it. In my constructor I have these two lines

{
     ...
     glCanvas.addGLEventListener(this);
     glCanvas.addMouseListener(this);
}

The GLEvent handling functions are being called appropriately, but I can’t get any mouse events at all. mousePressed is never entered. I’m not sure if this is related to Netbeans RCP modules–I’m told by others it’s not–but I’ve never had this situation happen. It’s fairly simple. Add the TopComponent to the GLCanvas mouse list, and mousePressed gets called. I’ve done it successfully in a normal Java app using JOGL. Does Netbeans RCP do anything funky to catch these mouse events?

I could think of the TopComponent or the windowing system to consume the mouse events.

I don’t understand this sentence. Do you mean, that the mouse listening works when you add the listener to the TopComponent. If so, what else do you need?

[quote]It’s fairly simple. Add the TopComponent to the GLCanvas mouse list, and mousePressed gets called.
[/quote]
This is what it’s supposed to do. If it worked fine, I wouldn’t have typed the part about not getting any mouse events. It’s a simple idea that’s not working and I’m not sure how to debug it because it’s simple. It’s clear I add the mouse listener to the the canvas, but I don’t get any mouse events when I click on it. That’s my problem.

Did you add the mouseListener methods to your class?such as the ones listed here?

http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html

Yes, I did. The TopComponent class had to be a MouseListener to be added the the GLCanvas mouse listeners, or else the compile shouldn’t have allowed the type. And the TopComponent had to implement the abstract functions in MouseListener, or it wouldn’t of compiled, right?

I’m kinda a noober but it sounds like you prolly just made a real small mistake somewhere.

If your code is small or you can get rid of all the parts that don’t matter to the current mouse issue your having I’m sure someone on here(maybe even me could help). just past it in here in code blocks. Otherwise I dunno what else to say.

well on second read here, because you have an abstract class with your mouseListener methods in it, still means you have to put the methods for them in your main-class(the class you need listening in). If you already did that then I am misunderstanding what you just last said.

ex:mainclass code


	public ClassNameConstructor(JFramedClass cg) { 
	    //Add mouse input device listeners 
	    cg.addMouseListener(new MouseListenerInterface() {
	    	public void onMouseClick(int x, int y){mouseClicked(x,y);}//<---Magic
	    });
	}
//Draw, init, reshape methods etc.

	public void mouseClicked(int imx, int imy) {//<-- more magic
		//see what I'm saying?
		System.out.println("X: " + imx + "\n Y: " + imy);
	}


|edit: | I just realized you said GLJPanel, I don’t know anything about that api or how it works so I may be at a loss for your goals, if that’s where the differences in code may be.

[quote]well on second read here, because you have an abstract class with your mouseListener methods in it, still means you have to put the methods for them in your main-class(the class you need listening in). If you already did that then I am misunderstanding what you just last said.
[/quote]
The class isn’t abstract, the methods it has to implement inheriting from MouseListener are. Because it isn’t an abstract class, it has to implement the mouse listener methods. The situation is I implement my class to as a GLEventListener and a MouseListener. I add my class to the GLCanvas twice. Only one listener works and not the other even though I set them up the same as I always have.

Here’s an example:


class MyTopComponent extends TopComponent implements GLEventListener, MouseListener
{
     public MyTopComponent() {
          initComponents(); // adds all the GUI stuff from the Matisse GUI builder including the GLCanvas called 'canvas'

          canvas.addGLEventListener(this);
          canvas.addMouseListener(this);
     }

     // methods I have to implement from MouseListener
     public void mousePressed(MouseEvent event) {
          System.out.println("This message is never seen");
     }
     .... other mouse methods

     // methods I have to implement from GLEventListener
     public void display(GLAutoDrawable drawable) {
          System.out.println("This message is seen and I can draw stuff");
          ...
     }
     .... other gl methods
}

I honestly don’t know.
Can I ask why you have two mouse listeners on the same panel? :persecutioncomplex:
Hopefully someone else can help you…

[quote]Can I ask why you have two mouse listeners on the same panel?
[/quote]
Two mouse listeners? I see one mouse listener. And I see one GLEventListener. Just like having one mouse listener and one mouse-motion listener. They handle different kinds of events. GLEventListener methods are called when the GLCanvas needs to be redrawn.

So I will probably in the end have a MouseListener, MouseMotionListener, KeyListener, and GLEventListener to respectively handle mouse clicks, mouse drags, key presses, and screen redraws. Make sense?

I’ve had similar trouble with a GLCanvas not invoking KeyboardListeners. This happens on Windows XP, but not Mac OS 10, so something weird is happening. I haven’t had a chance to look into yet, unfortunately; but you’re not crazy … ;D

Please tell me more about this. When I put some listeners onto a canvas, it works, I tested under XP and Vista too, not only under Linux.

I couldn’t say exactly. I wrote the code under the impression I was doing things pretty standard with my engine. I used the GLEventListener model for rendering, but would manually call display() instead of using an Animator. Then I would just have KeyListeners, MouseListeners, and MouseMotionListeners added to the canvas. For some reason, they picked nothing up using my XP box.

I didn’t have time to look further and I was content to just disable focus on the canvas and add the listeners to its Frame.

Since the canvas don’t have focus unless you click on it or call requestFocus() on it, this is the expected behaviour.

@voodoogiant
Try adding the mouse listener to the TopComponent:


this.addMouseListener(this); // Looks funny, but only because the TopComponent itself is your MouseListener

and report, if it works.

In my case, clicking to gain focus did nothing (I’m not sure if the click failed to give it focus, or if the listeners just failed to invoke). I have not tried using requestFocus() to give the GLCanvas focus.