I would like to know if there is a programmatically way to check if the mouse is over a component.
I would expect a button object already has something build in that I should be able to fetch?
The reason I need this is that I draw some custom components using a paintable canvas.
As an example, I use: event.source.parent.getComponent('btnOverlay').isFocusOwner() to check if my button is the focus owner, depending on that I draw a focus rectangle.
The way I do it now is by setting a custom property with the mouseEntered event and resetting the custom property with the mouseExited event.
The problem here is that if my button closes the window and I reopen it, it remains highlighted since the cutom property is not updating.
So a direct programmatically way should solve this.
Thanks in advance!
Yeah I'm aware of these component events. But they don't fully cover my issue. Since the mouseExit event does't occur whenever the page is closed on click.
Every Swing component has a
getMousePosition() method that returns a value if the mouse is directly over the component and null otherwise:
But the internalFrameDeactivated would work this way. Which is why I have used it instead of the mouseExit.
I really need to get better at exploring these docs.
You can do an on-close event or on-open event to reset all of the custom properties changed by the onMouseEnter/Exit events
Hi amarks, I'm also aware of that, but I'd rather figure it out on my custom component level than on the page event properties to keep everything within the object.