File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes jwindow, jscrollpane and jtable + mouse cursor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jwindow, jscrollpane and jtable + mouse cursor" Watch "jwindow, jscrollpane and jtable + mouse cursor" New topic
Author

jwindow, jscrollpane and jtable + mouse cursor

mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
i have a jwindow that contains a jscrollpane that contains a jtable.

what i want to do is to trigger the jwindow to close when the mouse cursor is not on top of it

i added a mouselistener to the jscrollpane but the method does not get called consistently

this is how i did it


i added +20 to the width of the rectangle to include the jscrollpane's jscrollbar's width

any ideas what i could be doing wrong? thanks


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this feels far from a good solution, but it seems to work OK (for now)

mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
thanks michael , that worked!

i tried to add the addAWTEventListener() but there is no such method available for JScrollPane

the jframe is actually the main root window

and there is a button in it, when clicked, the jwindow pops up and that is where id like the jwindow to be hidden if the mouse cursor is not on top of it anymore.

any ideas?

thanks!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i tried to add the addAWTEventListener() but there is no such method available for JScrollPane

it's a global listener, added to the toolkit - run the code, then move the pointer between the scrollpane
and the button, and back again - multiple mouseExited's fire


> and there is a button in it, when clicked, the jwindow pops up and that is where id like the jwindow to be hidden if the mouse cursor is not on top of it anymore.

the code should work for the above - basically when an exited is fired, a time delay (150ms), then the code checks if the current pointer position
is within the rectangle returned from window.getBounds()

may have to modify to add a check if the window is visible/showing
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
i got to modify your code to make it work

thanks a lot michael!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jwindow, jscrollpane and jtable + mouse cursor