Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Beautiful tooltip for TrayIcon

Beautiful tooltip for TrayIcon

Scheduled Pinned Locked Moved Java
help
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharkbc
    wrote on last edited by
    #1

    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 !

    4 1 Reply Last reply
    0
    • S sharkbc

      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 !

      4 Offline
      4 Offline
      4277480
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • 4 4277480

        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

        S Offline
        S Offline
        sharkbc
        wrote on last edited by
        #3

        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 !

        4 1 Reply Last reply
        0
        • S sharkbc

          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 !

          4 Offline
          4 Offline
          4277480
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • 4 4277480

            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

            S Offline
            S Offline
            sharkbc
            wrote on last edited by
            #5

            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

            4 1 Reply Last reply
            0
            • S sharkbc

              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

              4 Offline
              4 Offline
              4277480
              wrote on last edited by
              #6

              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

              S 1 Reply Last reply
              0
              • 4 4277480

                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

                S Offline
                S Offline
                sharkbc
                wrote on last edited by
                #7

                Thank you for a clear solution from Microsoft Tech. Im Still waiting for your "asking result" from Sun. Best regards !

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups