• Post Reply Bookmark Topic Watch Topic
  • New Topic

AWT Canvas, Objects, and MouseListeners  RSS feed

 
Cory Hartford
Ranch Hand
Posts: 85
Eclipse IDE Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone
I am working with an OSGI device that uses AWT as the GUI API. I've used it extensively but I have run across something that I can't figure out.
I have a component that I add a mouse listener to. I create an inner class that extends off of MouseAdapter to handle the events. In the mousePressed(MouseEvent e) method I use e.getSource() to get the component that fired the event.
I take that object and compare it to the original reference.

If I do this inside of a panel, everything is hunky dory. The objects are equal. However, when I place the same component into a panel that resides within a scroll pane, the objects don't test equal. Here are a couple of debug lines; the first is the source object from the MouseAdapter and the second line is the component object that I store when I instantiate it.

com.canon.meap.ctk.awt.CLabel[canvas23,420,44,67x20]
com.canon.meap.ctk.awt.CLabel[canvas24,420,44,67x20]

You can see that the canvases don't match and essentially I have two different objects. It has got to do with adding it to the panel in the scrollpane, but I don't understand why. It should be the same object; where I place it shouldn't make any difference.

Here are some code snippets that hopefully help illustrate what it is that I have



Build The ScrollPane and add the Panel


Instantiate the component


Handle the event




I guess that somehow adding the component to the panel within the scrollpane is somehow generating a new object and modifying it. That's the way it appears anyway. Just curious if someone can help me understand whats going on here. Thanks
 
Claude Moore
Ranch Hand
Posts: 877
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmm... just as workaround, what if you assign a name to the component and try and check names in you listener ?
This way you should get more hints about what happens under the hood... It looks strange a similar bug, even if with AWT on recent SO all may be possible..

 
Cory Hartford
Ranch Hand
Posts: 85
Eclipse IDE Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response Claude. I tried that and much to my surprise instead of the name I assigned the component, I ended up getting a canvas name. So yeah it must be a bug. What I ended up doing was just creating individual listeners for each component; for some reasons the listeners persist even though the object is changed/recreated or whatever is happening.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!