0

I'm working on a (legacy) Java-Swing application and ran into a problem:

The main GUI-component in this application is a Gantt chart, that displays tasks, as rectangles with a label, basically. A right-click on a task opens a context-menu, while hovering over a task with the mouse will show a customized, scrollable JTooltip. This constellation leads to my problem.

If I position the tool-tip too far away from the current mouse position, the tool-tip disappears, before I can move the mouse to one of the scroll-bar handles (horizontal/vertical). If I position the tool-tip too near to the current mouse position, the context menu won't open anymore, because the tool-tip hides the underlying task and the right-click is therefore captured by the tool-tip and not the task.

What I've tried so far:

  • searched for some kind of delay in ToolTipManager, to control how long the tool-tip is shown, after the mouse leaves the control, which triggered the tool-tip to be shown. As far as I can say, there is no such delay-property.
  • tried to find the right distance between tool-tip and current mouse position, so that the scroll-bar handles of the tool-tip can be reached and the context-menu is also shown. -> I found some distance, where both works, but often you have to try several times, until one can reach the scroll-bar handles.

So my question is: Is there any way to control when a JToolTip is hidden after the mouse leaves the corresponding component?

f.schmidt
  • 1
  • 1
  • Please edit your question to include a [complete example](http://stackoverflow.com/help/mcve) that exhibits the problem you describe. – trashgod Aug 12 '15 at 15:43

1 Answers1

1
  • create JWindow, better undecorated JDialog with correct modality (then could be easiest to catch MouseEvents)

  • only one window with setDefaultCloseOperation-DO_NOTHING_ON_CLOSE or HIDE_ON_CLOSE, by toggling only with setVisible false / true, to reuse this container for whole JVM instance, clear windows content before is setVisible(false) called

  • put there Swing Timer with (for example) 5-10 seconds for logical autoclosing, by testing SwingTimer.isRunning, if Mouse Scrolling continues and SwingTimer.isRunning returns true then to call SwingTimer.restart

  • override mouseClicked for whole JVM instance e.g.

    if (window.isVisible)
        window.getContentPane.removeAll() 
        window.setVisible(false)
    else
        someThingWithRealEventFromMouseListener 
    
  • there can be used some of better Listener that returns Boolean value instead of using low level instance of MouseListener

  • you can to (re)dispatch() mouse scrolling (only inside of Bound of the current parent - JFrame, JDialog) to the popup window, by using two - three methods from SwingUtilities

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319