Beautiful tooltip for TrayIcon
-
Hi everybody ! Im now using TrayIcon . The tooltip message display two caption and the image belong to Message Type as bellow. -Title :String -Message :String. -MessageType:INFO,WARNING,ERROR,NONE. I now want to dis play the tooltip message with two caption and the Icon image that i specify the path as bellow: -Title :String -Message :String. -IconImage : IconImage or path of the image. Can anybody help me. Thanks very much ! Best regards !
-
Hi everybody ! Im now using TrayIcon . The tooltip message display two caption and the image belong to Message Type as bellow. -Title :String -Message :String. -MessageType:INFO,WARNING,ERROR,NONE. I now want to dis play the tooltip message with two caption and the Icon image that i specify the path as bellow: -Title :String -Message :String. -IconImage : IconImage or path of the image. Can anybody help me. Thanks very much ! Best regards !
In short if the TrayIcon class was a JComponent then you can simply apply html tags to it. Therefore, to simulate what you need I will use the jdic.jar from https://jdic.dev.java.net/servlets/ProjectDocumentList?expandFolder=4183&folderID=5497.
import javax.swing.*;
import org.jdesktop.jdic.tray.*;
import java.awt.BorderLayout;
import java.awt.event.*;public class SystemTrayDemo extends JFrame
{
public TrayIcon trayIcon;
public JDialog dialog;public SystemTrayDemo() { JPopupMenu menu = new JPopupMenu("Menu"); JMenuItem menuItem1 = new JMenuItem("Menu1"); menu.add(menuItem1); JMenuItem menuItem2 = new JMenuItem("Menu2"); menu.add(menuItem2); JMenuItem menuItem3 = new JMenuItem("Menu3"); menu.add(menuItem3); JMenuItem menuItem4 = new JMenuItem("Exit"); menu.add(menuItem4); menuItem4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.exit(0); } }); ImageIcon icon = new ImageIcon("middle.gif"); trayIcon = new TrayIcon(icon, "Hello System Tray", menu); SystemTray tray = SystemTray.getDefaultSystemTray(); tray.addTrayIcon(trayIcon); trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog = new JDialog(); dialog.add(new JLabel("Title"), BorderLayout.NORTH); dialog.add(new JLabel("Message"), BorderLayout.CENTER); dialog.add(new JLabel(new ImageIcon("middle.gif")),BorderLayout.SOUTH); dialog.setLocation(trayIcon.getLocationOnScreen().x - 50,trayIcon.getLocationOnScreen().y - 105); dialog.setVisible(true); dialog.setSize(100, 100); dialog.setResizable(false); dialog.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { dialog.dispose(); } }); } }); } public static void main(String\[\] args) { new SystemTrayDemo(); }
}
The presentation of it is close to aero peek in windows 7. Hope this helps. Regards
-
In short if the TrayIcon class was a JComponent then you can simply apply html tags to it. Therefore, to simulate what you need I will use the jdic.jar from https://jdic.dev.java.net/servlets/ProjectDocumentList?expandFolder=4183&folderID=5497.
import javax.swing.*;
import org.jdesktop.jdic.tray.*;
import java.awt.BorderLayout;
import java.awt.event.*;public class SystemTrayDemo extends JFrame
{
public TrayIcon trayIcon;
public JDialog dialog;public SystemTrayDemo() { JPopupMenu menu = new JPopupMenu("Menu"); JMenuItem menuItem1 = new JMenuItem("Menu1"); menu.add(menuItem1); JMenuItem menuItem2 = new JMenuItem("Menu2"); menu.add(menuItem2); JMenuItem menuItem3 = new JMenuItem("Menu3"); menu.add(menuItem3); JMenuItem menuItem4 = new JMenuItem("Exit"); menu.add(menuItem4); menuItem4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.exit(0); } }); ImageIcon icon = new ImageIcon("middle.gif"); trayIcon = new TrayIcon(icon, "Hello System Tray", menu); SystemTray tray = SystemTray.getDefaultSystemTray(); tray.addTrayIcon(trayIcon); trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog = new JDialog(); dialog.add(new JLabel("Title"), BorderLayout.NORTH); dialog.add(new JLabel("Message"), BorderLayout.CENTER); dialog.add(new JLabel(new ImageIcon("middle.gif")),BorderLayout.SOUTH); dialog.setLocation(trayIcon.getLocationOnScreen().x - 50,trayIcon.getLocationOnScreen().y - 105); dialog.setVisible(true); dialog.setSize(100, 100); dialog.setResizable(false); dialog.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { dialog.dispose(); } }); } }); } public static void main(String\[\] args) { new SystemTrayDemo(); }
}
The presentation of it is close to aero peek in windows 7. Hope this helps. Regards
Hi ! I think you didn't understand my question. I want to display the IconImage on the top-left of the title . For example,
trayIcon = new TrayIcon(icon, "Hello System Tray", menu);
must be change to
trayIcon = new TrayIcon(icon, "
Hello System Tray",menu);
if we can use html tags in our code ! Thanks anyways ! Can anybody help me ? Best regards !
-
Hi ! I think you didn't understand my question. I want to display the IconImage on the top-left of the title . For example,
trayIcon = new TrayIcon(icon, "Hello System Tray", menu);
must be change to
trayIcon = new TrayIcon(icon, "
Hello System Tray",menu);
if we can use html tags in our code ! Thanks anyways ! Can anybody help me ? Best regards !
I understood your question, if you read my first line "If the trayicon class was a Jcomponent then we can use html tags". You can display (as a balloon) the message type error,info,etc... use these in place of the dialog code depending on type:
trayIcon.displayMessage("Title", "Message", trayIcon.INFO_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.NONE_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.WARNING_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.ERROR_MESSAGE_TYPE);otherwise what your asking can only be done if you write your own package. Regards
-
I understood your question, if you read my first line "If the trayicon class was a Jcomponent then we can use html tags". You can display (as a balloon) the message type error,info,etc... use these in place of the dialog code depending on type:
trayIcon.displayMessage("Title", "Message", trayIcon.INFO_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.NONE_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.WARNING_MESSAGE_TYPE);
trayIcon.displayMessage("Title", "Message", trayIcon.ERROR_MESSAGE_TYPE);otherwise what your asking can only be done if you write your own package. Regards
If using a JDialog or JFrame or JPanel to display an image(instead of the tooltip of TrayIcon) i think it is very simple and i didn't post my question. I posted this question because i saw the "beautiful tooltip" of trayIcon of windowXP "your computer might be at risk". The Iconimage of the tooltip is not in (WARNING,INFO,ERROR,NONE) images. I'm waiting for a solution for this because Microsoft did it ! Any other ideas ? Best regards !
modified on Friday, September 11, 2009 12:42 AM
-
If using a JDialog or JFrame or JPanel to display an image(instead of the tooltip of TrayIcon) i think it is very simple and i didn't post my question. I posted this question because i saw the "beautiful tooltip" of trayIcon of windowXP "your computer might be at risk". The Iconimage of the tooltip is not in (WARNING,INFO,ERROR,NONE) images. I'm waiting for a solution for this because Microsoft did it ! Any other ideas ? Best regards !
modified on Friday, September 11, 2009 12:42 AM
I was cruising around to see if their is any third party packages that can do what your asking and I stumbled upon an article on codeproject.com but its not in Java its using windows pressentation foundation but it does exaclty what you ask: http://www.codeproject.com/KB/WPF/wpf\_notifyicon.aspx All you need now is to get Visual C# express and get the risk icon (what i did in windows 7 rc go to windows firewall and click on turn of firewall you will get the red x snap it using the snap tool and go to photoshop to do some editing and you can then save it as 16 x 16 icon and name it Inactive.ico) then copy it and place it in the c:\...wpf-notifyicon\Sample Project\Icons folder, then rebuild the code and run, you will find at the bottom right corner custom notification message. Hope this helps. I will try to ask sun about it but you said it your self Microsoft did it with their language not Java Regards
-
I was cruising around to see if their is any third party packages that can do what your asking and I stumbled upon an article on codeproject.com but its not in Java its using windows pressentation foundation but it does exaclty what you ask: http://www.codeproject.com/KB/WPF/wpf\_notifyicon.aspx All you need now is to get Visual C# express and get the risk icon (what i did in windows 7 rc go to windows firewall and click on turn of firewall you will get the red x snap it using the snap tool and go to photoshop to do some editing and you can then save it as 16 x 16 icon and name it Inactive.ico) then copy it and place it in the c:\...wpf-notifyicon\Sample Project\Icons folder, then rebuild the code and run, you will find at the bottom right corner custom notification message. Hope this helps. I will try to ask sun about it but you said it your self Microsoft did it with their language not Java Regards