• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AWT Canvas, Objects, and MouseListeners

 
Ranch Hand
Posts: 85
Mac Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1359
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic