• 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

clicking on icons does not work

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a panel with ImageIcons. When I click on the panel, I get the coordinates where I clicked, but when I click directly on the icons, nothing happens. This is part of a larger program(>4000 lines of code). I want to get feedback when I clicked on the icons. I hope this problem is not too complex.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you have anything to do with a mouselistener on the labels e.g. tooltips,
the mouseEvent is consumed and not passed to the panel.
 
Marc Beck
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for pointing that out. That must be the reason, because I just recently added tooltips on my ImageLabels, and I think everything worked alright before then. How can I get around the problem? I am sure there must be a way somehow.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
depending on how many labels you have, the easy way
might be to just add a mouseListener to the label,
then dispatch the event to the panel

 
Marc Beck
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this now:



and I get the following error message:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)
if ImagePanel is the panel with the icons
ImagePanel.add(IconLabel);

then you need to dispatch the event to ImagePanel
//panel.dispatchEvent(me);
ImagePanel.dispatchEvent(me);

2)
"...is not abstract..."
any time you 'implement' an interface, you have to handle each method (can be empty)
easy fix is to, instead, use the built-in class that provides empty methods for the interface

//class IconMouseListener implements MouseListener{
class IconMouseListener extends MouseAdapter{

3)
whatever method you are listening to in your panel's mouseListener (to get the co-ords),
the method you dispatch from must be the same
mousePressed() --> mousePressed()
etc
 
Marc Beck
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed it to:



The error message is gone, but still nothing happens when I click on the icons.I am sure that ImagePanel is the correct panel, because that is the one that contains the icons and that has the main MouseListener. Thanks for your help and for being patient.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just posted this at sun's forum (response to a different problem),
so it's an easy copy/paste

<copy/paste>
if this is the part not working
public void mouseClicked ( MouseEvent e ) {
be aware that mouseClicked does not always fire.

mousePressed event fires first, then mouseReleased, then
if the coords of pressed/released match, mouseClicked fires.
so, the mouse only has to move 1 pixel up/down/left or right
between press and release and mouseClicked won't fire.
</copy/paste>

make a small sample program - frame/panel/image with some listeners
to just print something to the console and see if it works OK for
mousePressed. if OK, you should be able to modify your actual code
to mousePressed

<EDIT>
to make it a bit easier, here's the dummy program to test
(just change the code or image file name to match)

then click anywhere on the panel or the image, and "OK" should print in the console

[ February 21, 2008: Message edited by: Michael Dunn ]
 
We begin by testing your absorbancy by exposing you to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic