I have a very specific question: I want to be able to, via a method call, popup a tooltip with text(it could say anything) in a given location on the screen for a certain amount of time on method call(say the logic is in a talk method) and fades away. How could I go about that? Is there a way to do it via JTooltip? Or would I have to dive into JNA to get what I want?
I should mention I want the tooltip to popup with text in a given location without the cue of a mouse over, like a popup.
Also, in case a tooltip is not the right way to go about what I want (which I hope I made clear), is there a more effective alternative?
There are few ways this might be achieved. One possible way is through the use of a transparent
JWindow
and a SwingTimer
Basically, what this does is creates a
JWindow
, set's it's background color to fully transparent, making a transparent window. It then uses simpleBackgroundPane
(to render a nice background) andMessagePane
to hold the actual message. You can do this in one panel, but I like the flexibility this affords me.Now, personally, I would create a simpler API which could build the popup window and create a
Timer
with a variable delay, but you get the ideaYou could play with a
AlphaComposite
on the background panel to create a semi transparent backgroundPopup window using a 50%
AlphaComposite
Updated
You could use a factory or builder pattern to provide a simple API, for example...
The builder would collect the properties you want to specify, provide defaults where you didn't set them and then would show the final popup.
The basic idea is when you call
show
, it would collect the properties and build the window similar to how the constructor works right now...Updated with a fading popup window
This is (a somewhat over the top) example of how you might be able to produce a fading in/out effect. The example guarantees that the message will be on the screen (full) for at specified delay period
Now, you probably also do this by changing the maximum opacity level of the frame, but, if you change the
paintComponent
of theBackgroundPane
you can also effect the over opacity of the popup message. This method will only effect the background, not the message text...