views:

260

answers:

2

Hi,

I wrote an application and now I'm making a tray-icon. Now I want to set a multi-line tooltiptext to the tray-icon. But I don't know how. I know how to do this with Swing:

component.setToolTipText("<html>Line 1<br>Line2</html>");

But this doesn't work with AWT. Also serarating lines by \n doesn't work.

I'm running on linux:

Ubuntu 10.04
Kernel Linux 2.6.32-22-generic
GNOME 2.30.0
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Server VM (build 14.0-b16, mixed mode)

Any help would be very appreciated.
Thanks

A: 

JToolTip derives from JComponent, but you can simulate the effect yourself using Graphics-only methods, as shown in the AlphaView class of this example.

trashgod
+3  A: 

The following code produced a perfectly fine multi line tooltip for me:

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class AWTScratch {
    public static void main(String[] args) {
        BufferedImage im = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
        TrayIcon ti = new TrayIcon(im, "Multiline\nmulti");
        ti.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        ti.setImageAutoSize(true);
        if (SystemTray.isSupported()){
            SystemTray st=SystemTray.getSystemTray();
            try {
                st.add(ti);
            } catch (AWTException e1) {
                e1.printStackTrace();
            }
        }
    }
}

Maybe its a platform issue. Could you give us your OS and jvm version? Seems to be a bug, see inside suns bug database.

ablaeul
+1 Works on Mac, too.
trashgod