GithubHelp home page GithubHelp logo

priyankt3i / java-systemtray Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dualcon/java-systemtray

0.0 0.0 0.0 3 KB

Java - how to work with System Tray.

License: MIT License

Java 100.00%

java-systemtray's Introduction

SystemTray

How to Use the System Tray.

The system tray is a specialized area of the desktop where users can access currently running programs. This area may be referred to differently on various operating systems. On Microsoft Windows, the system tray is referred to as the Taskbar Status Area, while on the GNU Network Object Model Environment (GNOME) Desktop it is referred to as the Notification Area. On K Desktop Environment (KDE) this area is referred to as the System Tray. However, on each system the tray area is shared by all applications running on the desktop. More information can be found on https://docs.oracle.com/.

SystemTrayManager.java

package com.wikidreams.systemtray;

import java.awt.AWTException; import java.awt.MenuItem; import java.awt.PopupMenu; import java.awt.SystemTray; import java.awt.TrayIcon; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.ImageIcon;

public class SystemTrayManager {

private static TrayIcon trayIcon;
private static PopupMenu menu;
private static ImageIcon icon;
private static String iconTitle = "Demo";
private static String baloonTitle = "Application";
private static String ballonMessage = "Running on system tray.";

public static void CreateSystemTrayManager() {
	if (! SystemTray.isSupported()) {
		System.out.println("The system does not supports system tray.");
		System.exit(0);
	}
	CreateSystemTrayMenu();
}


private static void CreateSystemTrayMenu() {
	menu = new PopupMenu();

	MenuItem exitItem = new MenuItem("Exit");
	exitItem.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	});

	menu.add(exitItem);
	CreateSystemTrayIcon();
}


private static void CreateSystemTrayIcon() {
	icon = new ImageIcon("images/icone.gif");
	trayIcon = new TrayIcon(icon.getImage(), iconTitle, menu);
	trayIcon.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			if (e.getClickCount() == 2) {
				SystemTray.getSystemTray().remove(trayIcon);
			} 
		}            
	});
	AddToSystemTray();
}


private static void AddToSystemTray() {
	try {
		SystemTray.getSystemTray().add(trayIcon);
		trayIcon.displayMessage(baloonTitle, ballonMessage, TrayIcon.MessageType.INFO);
	} catch (AWTException ex) {
		System.out.println(ex.getMessage());
	}
}

}

App.java

package com.wikidreams.systemtray;

public class App {

public static void main(String[] args) {
	SystemTrayManager.CreateSystemTrayManager();		
}

}

Produced by Wiki Dreams.github.io.

java-systemtray's People

Contributors

dualcon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.