Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

tooltip consumes mouse events?

Thread view: 
Peter Ashford - 13 Aug 2007 22:40 GMT
Hi there,

I have a jframe with a mouse listener on it. I use mouse events to
allow the user to drag the frame around the screen.  This all works
fine, but I added some code to set a tooltip for the frame on the
mouse entered method like so:

 public void mouseEntered(MouseEvent e){
        Date now = new Date();
        String toolTipTxt = String.format("%tA %te %tB %tY", now,
now, now, now);
        frame.getRootPane().setToolTipText(toolTipTxt);
        frame.setCursor(moveCursor);
       }

...and this seems to end up consuming all of the mouse events, so that
I now cannot move my frame (nor launch the popup menu attached to it
via a rightclick action)

Is this correct behaviour?  If so, how should one add a tooltip to a
frame with a mouselistener on it?

Thanks!

I'm using Java 1.6.
Thomas Hawtin - 14 Aug 2007 03:45 GMT
> ...and this seems to end up consuming all of the mouse events, so that
> I now cannot move my frame (nor launch the popup menu attached to it
> via a rightclick action)

(Popup events are not necessarily right click actions - you should test
all mouse events for isPopupTrigger.)

> Is this correct behaviour?  If so, how should one add a tooltip to a
> frame with a mouselistener on it?

Unfortunately it is the expected broken behaviour for mouse and mouse
motion events. Adding a mouse listener stops the events bubbling up the
component-container hierarchy. Actually setComponentPopupMenu (since
1.5) should be alright as it uses AWTEventListeners.

Some of your choices are:

 o Add the mouse listeners at exactly the same level as other mouse
listeners. You may need to play about with ContainerListener to achieve
this.
 o Add an AWTEventListener. This requires security permissions.
 o Push an EventQueue with an overridden dispatchEvent method. this
doesn't stack well with similar code and prevents system copy & paste
working in sandboxed environments.

Tom Hawtin
Peter Ashford - 14 Aug 2007 12:15 GMT
> > ...and this seems to end up consuming all of the mouse events, so that
> > I now cannot move my frame (nor launch the popup menu attached to it
> > via a rightclick action)
>
> (Popup events are not necessarily right click actions - you should test
> all mouse events for isPopupTrigger.)

Noted :o)

> > Is this correct behaviour?  If so, how should one add a tooltip to a
> > frame with a mouselistener on it?
[quoted text clipped - 3 lines]
> component-container hierarchy. Actually setComponentPopupMenu (since
> 1.5) should be alright as it uses AWTEventListeners.

I've switched to using a JWindow (didn't want a taskbar icon) and all
my mouse events are working, I'm just not getting the tooltip.

> Some of your choices are:
>
>   o Add the mouse listeners at exactly the same level as other mouse
> listeners. You may need to play about with ContainerListener to achieve
> this.

I'm not quite sure what you mean by this - I'm not familiar with
ContainerListener - what should I do with it?

I figured that one other option is that since I'm getting the mouse
events ok, I could start a thread in MouseEntered waiting for a
hovering mouse and then throw up a custom tooltip (just another
undecorated JWindow)

Thanks for the thoughts, by the way - I appreciate the ideas.
Thomas Hawtin - 14 Aug 2007 15:38 GMT
> I've switched to using a JWindow (didn't want a taskbar icon) and all
> my mouse events are working, I'm just not getting the tooltip.

Not entirely sure why. Obviously the PL&F will add some mouse listeners
to components of a JFrame. Perhaps there is a problem with Window having
an owner despite it being a top-level component (which is a bit confusing).

Looking at the bug database it looks as if in 1.5 (only) "setToolTipText
does not work if the component is not focussed". The bug database is
down at the moment, but it is in the google cache.

http://64.233.183.104/search?q=cache:UJHZspzxbFQJ:bugs.sun.com/bugdatabase/view_
bug.do%3Fbug_id%3D6178004+6178004+java&hl=en&ct=clnk&cd=1&gl=uk&client=firefox-a


> I'm not quite sure what you mean by this - I'm not familiar with
> ContainerListener - what should I do with it?

If one adds a mouse listeners to a hierarchy of components, and then add
(or remove) a component, that component will need a listener added (or
removed). Container listeners will indicate when a component is added or
removed.

Tom Hawtin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.