JToolTip

Hello.

I’m using and AWT Canvas and a Swing JToolBar.
The ToolBar is over the Canvas.
The Problem is if you want to read the ToolTip of a Button in the ToolBar the ToolTip will be displayed behind the Canvas. How can i fix this?
menues have the option to set them heavyweight but ToolTips?
Any Ideas?

why do you use canvas and not a JPanel?

Heavyweight is always more heavy than lightweight :wink:

lg Clemens

because i want to paint some stuff dynamical.
how should i do this with a JPanel?

of course it will be easier if only
swing elements are working together, but sun says:
“which class has not a direct equivalent in Swing? -> Canvas!”

To paint dynamically on a JComponent (or any subclass) , you just have to override paintComponent(Graphics).

And that’s all.

For your tooltip problem, you can use TooltipManager.sharedInstance().setLightWeightPopupEnabled(false).

Lilian

IIRC, you can set tooltips to be heavyweight in the same way that you set JPopupMenus to be heavyweight. (Search!)

Thanks Lilian,

i know that i can override the paintComponent() function to draw my own stuff, but i am using a bufferstrategy and i think swing elements have their own buffering which is maybe not efficient enough for my purpose. and i am using a separate thread for painting and swing is known for beeing not thread-safe.
do you have any experiences with that?
Also thanks for saying how to switch the tooltips to heavyweight.

@orangy Tang:
i have searched before i posted here, but thanks for your great help. :wink:

It seems mixing components is your solutions for performance.

I have ran into the same kind of problems, and found a good solution was :

  • don’t use any overlapping in your application (JInternalFrame is your ennemy).

  • enable all workarounds for tooltips, popups

[warning probable shameless plug :wink: ]
At work, I use a docking framework of my company (I’m the author) to overcome the internal frames problems (but it’s not the main reason).
I’ve patched it recently to support that kind of AWT/Swing mixing (the version including this patch will be released later on this week).
[/plug]

yes, the mixing of awt/swing is now my solution because there is no swing class which is capable to do the stuff i need but canvas does.

i have tried JInternalFrame but the repaint of the DesktopPane was to bad so i don’t want to use it.

what do you mean with workarounds for tooltips and popups? this heavyweight things or is there more to do?

(in our company we are using a docking framework, too.
but i’m not the author) :wink:

everything which AWT can do SWING also does. Get rid of your AWT hack, its really old and in my mind “canvas” should be marked as deprecated.

lg Joe

There’s another workaround for JPopUpMenu (setLightWeightPopUpEnabled(false) as OrangyTang said earlier).

Also, if you want to overlay components (including swing and AWT) you can since java 1.5 with Container.setComponentZOrder(), but it requires some tweaks (the overlapping swing component must belong to different heavyweight containers (Panel) ). It’s what I’ve done to enable auto-expand/maximize component in the docking framework.
But with that patch, the code is not as readable as before : I’m now waiting for mustang which is said to support AWT/swing mixing.

Lilian

@Garage_Joe:

maybe you are right but maybe not, because if canvas should be marked as deprecated why there are thousands of experienced programmers which think that it is the best solution?
and if swing everything can do what awt does, why is it not thread-safe?

if you already implemented a canvas-like JPanel with a BufferStrategy and a Painting-Thread, i would be happy if you can give me some tips.

Because it takes a long time till experienced programmers come to the conclusion that the way they did it till they started isn’t the best anymore.
Have a look at yourself :wink:

Well, AWT isn’t thread-safe either. It was designed to be thread-safe but it soon turned out that this was a BAD desision and some hacks to allow AWT stuff to be used from many threads was even removed in 1.2+!
So in most situations it will work but it is really not recommended. In Swing the removed thread-safty from the beginning to avaoid the mistakes made with AWT.
Multi-Threaded Graphics is never a good idea, at least on all underlaying graphic subsystems AWT is supported on.
Rendering is always done only with a single thread down to the hardware!

No I haven’t. But if you really need to draw from multiple threads maybe your design is broken anyway?

lg Joe