Set Popup value to show on hover.
-
Hi there!
I'm looking for a way to set popup values to appear when the mouse hovers over the component, rather than only on click/drag.
Preferably with a one-second delay, kind of like a tooltip.
I tried using an if (event.hover) in the LAF, but it didn't work.
Does anyone know how to do this?
-
@CyberGen I don't have the exact code with me right now but I've previous used the text label to do something like this:
if (obj.hover || obj.clicked) { labelText = obj.valueAsText; }
-
@CyberGen create a timer object. if you're not using a panel, create one in its own variable. if you are, the panel already has one.
your if (event.hover) should now save a variable that says hover = 1 and start the timer. give it a time of 100ms or so.
if you're using the panel, do it inside the mouse callback. if not, create a mouse broadcaster that will do this and attach the components that you want to exhibit this behavior to the broadcaster. if you're using control helpers, you can call .attach.. for each control inside the function i.e. you don't have to pass all the controls to it within a single call.
your timer should have pretty much a few lines:
if (time since timer start > target time && hover == 0)
{
stopTimer()
repaint component
}you now query whether the timer is running to decide whether to show the label in your LAF/PR.
there's a bunch of ways to approach this, but they all involve a timer. you can trigger the timer if event.hover == 0 so when the mouse leaves the component, it starts the timer, but you should now be querying both the timer and the hover variable you're setting.
remember, the some event properties like event.clicked only fire when you click. event.hover will say true pretty much for every callback except when you move the mouse away.
-
@aaronventure Oh this is perfect. Thank you very much for the detailed instruction. I'll dive into it and let you know how it goes.