4 Replies - 388 Views - Last Post: 08 February 2018 - 05:38 AM Rate Topic: -----

#1 patriotaki  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 179
  • Joined: 08-October 14

How to disspear System Tray Notification?

Posted 08 February 2018 - 01:53 AM

Hello how can i make a system tray notifcation dissapear after X seconds?
in windows they dissapear fine but in MAC OS i have to press ok to close them
Tray td = new Tray();
td.displayTray("Heello");

Is This A Good Question/Topic? 0
  • +

Replies To: How to disspear System Tray Notification?

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3541
  • View blog
  • Posts: 16,135
  • Joined: 20-September 08

Re: How to disspear System Tray Notification?

Posted 08 February 2018 - 02:55 AM

Sorry but there's no class Tray in the JDK
Was This Post Helpful? 0
  • +
  • -

#3 patriotaki  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 179
  • Joined: 08-October 14

Re: How to disspear System Tray Notification?

Posted 08 February 2018 - 04:13 AM

View Postg00se, on 08 February 2018 - 02:55 AM, said:

Sorry but there's no class Tray in the JDK

I use this one
https://docs.oracle....SystemTray.html

I want to make it dissapear like in windows but in mac osx i have to click ok
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3541
  • View blog
  • Posts: 16,135
  • Joined: 20-September 08

Re: How to disspear System Tray Notification?

Posted 08 February 2018 - 04:55 AM

Please in future post your real code or it just wastes people's time

As to your question, you could try changing the look and feel. Otherwise it will use the platform's system tray and if that's what Apple does then ...
Was This Post Helpful? 0
  • +
  • -

#5 patriotaki  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 179
  • Joined: 08-October 14

Re: How to disspear System Tray Notification?

Posted 08 February 2018 - 05:38 AM

Tray.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package igbotv4;

import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.net.MalformedURLException;
import javax.swing.JOptionPane;

/**
 *
 * @author George
 */
public class Tray {
    
    
    
    public void displayTray(String s) throws AWTException, MalformedURLException {
        //Obtain only one instance of the SystemTray object
        SystemTray tray = SystemTray.getSystemTray();

        //If the icon is a file
        Image image = Toolkit.getDefaultToolkit().createImage("lib/icon.png");
        //Alternative (if the icon is on the classpath):
        

        TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
        //Let the system resize the image if needed
        trayIcon.setImageAutoSize(true);
        //Set tooltip text for the tray icon
       
        trayIcon.setToolTip("System tray icon demo");
        tray.add(trayIcon);
        trayIcon.displayMessage("Hello", s, TrayIcon.MessageType.INFO);
    }
}




Main.java
Tray td = new Tray();
td.displayTray("Hello World");




the notification in Windows goes away automatically but in MAC OS i have to click OK..although in windows there is no OK Button
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1