當前位置: 首頁>>代碼示例>>Java>>正文


Java SystemTray.add方法代碼示例

本文整理匯總了Java中java.awt.SystemTray.add方法的典型用法代碼示例。如果您正苦於以下問題:Java SystemTray.add方法的具體用法?Java SystemTray.add怎麽用?Java SystemTray.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.SystemTray的用法示例。


在下文中一共展示了SystemTray.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initSystemTray

import java.awt.SystemTray; //導入方法依賴的package包/類
private static void initSystemTray() {
  // add system tray icon with popup menu
  if (SystemTray.isSupported()) {
    SystemTray tray = SystemTray.getSystemTray();
    PopupMenu menu = new PopupMenu();
    MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
    exitItem.addActionListener(a -> Game.terminate());
    menu.add(exitItem);

    trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
    trayIcon.setImageAutoSize(true);
    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:19,代碼來源:Program.java

示例2: initUI

import java.awt.SystemTray; //導入方法依賴的package包/類
/**
 * Init Swing UI
 */
private void initUI() {
	URL url = null;
	if (ConfigIO.getInstance().isUseDarkIcon()) {
		url = Dropzone.class.getResource("/images/sds_logo_dark.png");
	} else {
		url = Dropzone.class.getResource("/images/sds_logo_light.png");

	}
	if (Util.getOSType() == OSType.MACOS) {

	}

	trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(url), I18n.get("tray.appname"),
			new TrayPopupMenu());
	trayIcon.setImageAutoSize(true);

	final SystemTray tray = SystemTray.getSystemTray();
	try {
		tray.add(trayIcon);
	} catch (AWTException e) {
		LOG.error("TrayIcon could not be added.");
		System.exit(1);
	}
}
 
開發者ID:michaelnetter,項目名稱:dracoon-dropzone,代碼行數:28,代碼來源:Dropzone.java

示例3: startTray

import java.awt.SystemTray; //導入方法依賴的package包/類
private static void startTray()
{
	SystemTray tray = SystemTray.getSystemTray();
	int w = 80;
	int[] pix = new int[w * w];
	for (int i = 0; i < w * w; i++)
		pix[i] = (int) (Math.random() * 255);
	ImageProducer producer = new MemoryImageSource(w, w, pix, 0, w);
	Image image = Toolkit.getDefaultToolkit().createImage(producer);
	TrayIcon trayIcon = new TrayIcon(image);
	trayIcon.setImageAutoSize(true);
	startWindow();
	try
	{
		tray.add(trayIcon);
		System.out.println("installed tray");
	}
	catch (AWTException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:24,代碼來源:HelloWorld.java

示例4: TimeTray

import java.awt.SystemTray; //導入方法依賴的package包/類
/**
 * TimeTray Constructor
 */
public TimeTray() {
    // retrieve iconSize of SystemTray
    SystemTray systemTray = SystemTray.getSystemTray();
    iconSize = systemTray.getTrayIconSize();

    // set presets
    presets = new Presets(iconSize.height);

    calendar = Calendar.getInstance();

    // create TrayIcon according to iconSize
    trayIcon = new TrayIcon(getTrayImage(), "TimeTray", menu);
    try {
        systemTray.add(trayIcon);
    } catch (AWTException ex) {
        ex.printStackTrace();
    }

    // run thread and set timer tooltip to update every second
    run();

    Timer timer = new Timer();
    timer.schedule(this, 1000, 1000);
}
 
開發者ID:otacke,項目名稱:timetray,代碼行數:28,代碼來源:TimeTray.java

示例5: AWTrayIcon

import java.awt.SystemTray; //導入方法依賴的package包/類
/**
 * @param frame2
 * @param icon
 * @param title
 * @throws AWTException
 */
public AWTrayIcon(final JFrame frame, final Image icon, final String title) throws AWTException {
    this.frame = frame;
    eventSender = new BasicEventSender<AWTrayIcon>();
    final SystemTray systemTray = SystemTray.getSystemTray();
    /*
     * trayicon message must be set, else windows cannot handle icon right
     * (eg autohide feature)
     */
    trayIcon = new ExtTrayIcon(icon, title);

    trayIcon.addMouseListener(this);
    trayIcon.addTrayMouseListener(this);

    systemTray.add(trayIcon);
}
 
開發者ID:friedlwo,項目名稱:AppWoksUtils,代碼行數:22,代碼來源:AWTrayIcon.java

示例6: initTray

import java.awt.SystemTray; //導入方法依賴的package包/類
private void initTray() {
	final SystemTray systemTray = SystemTray.getSystemTray();
	final TrayIcon trayIcon = new TrayIcon(getImage("icon.gif"), "Deskshare is running");
	trayIcon.setImageAutoSize(true); // Autosize icon base on space
									 // available on tray
	MouseAdapter mouseAdapter = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent evt) {
			// This will display small popup message from System Tray
			trayIcon.displayMessage("BigMarker Deskshare", "This is an info message", TrayIcon.MessageType.INFO);
			if (!app.isVisible()) {
				app.setVisible(true);
			}
		}
	};
	trayIcon.addMouseListener(mouseAdapter);
	try {
		systemTray.add(trayIcon);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:BigMarker,項目名稱:deskshare-public,代碼行數:23,代碼來源:SmallUI.java

示例7: initTray

import java.awt.SystemTray; //導入方法依賴的package包/類
private void initTray() {
	final SystemTray systemTray = SystemTray.getSystemTray();
	final TrayIcon trayIcon = new TrayIcon(getImage("icon.gif"), "Deskshare is running");
	trayIcon.setImageAutoSize(true); // Autosize icon base on space available on tray
	MouseAdapter mouseAdapter = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent evt) {
			System.out.println("icon clicked: " + evt.getClickCount());
			// This will display small popup message from System Tray
			trayIcon.displayMessage("BigMarker Deskshare", "This is an info message", TrayIcon.MessageType.INFO);
			if (!app.isVisible()) {
				app.setVisible(true);
			}
		}
	};
	trayIcon.addMouseListener(mouseAdapter);
	try {
		systemTray.add(trayIcon);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:BigMarker,項目名稱:deskshare-public,代碼行數:23,代碼來源:DebugUI.java

示例8: init

import java.awt.SystemTray; //導入方法依賴的package包/類
/**
 * Initializes the tray
 */
public void init() {

	if (SystemTray.isSupported()) {

		SystemTray tray = SystemTray.getSystemTray();

		if (tray.getTrayIcons().length == 0) {

			String iconFileName = resources.getImagePath() + File.separator
					+ "MidiAutomatorIcon16.png";
			image = Toolkit.getDefaultToolkit().getImage(iconFileName);
			trayPopupMenu.init();
			trayIcon = new TrayIcon(image, NAME);
			trayIcon.addMouseListener(trayMouseListener);

			try {
				tray.add(trayIcon);
			} catch (AWTException e) {
				log.error("Error on adding tray icon.", e);
			}
		}
	}
}
 
開發者ID:aguelle,項目名稱:MIDI-Automator,代碼行數:27,代碼來源:Tray.java

示例9: addToTray

import java.awt.SystemTray; //導入方法依賴的package包/類
/**
 * Fügt dieses WollMuxBarTrayIcon zur SystemTray hinzu (sofern die SystemTray auf
 * dem aktuellen System supportet ist).
 * 
 * @throws UnavailableException
 *           wenn die SystemTray nicht verfügbar ist.
 * 
 * @author Daniel Benkmann (D-III-ITD-D101)
 */
public void addToTray() throws UnavailableException
{
  if (!SystemTray.isSupported())
  {
    throw new UnavailableException(L.m("System Tray ist nicht verfügbar!"));
  }
  SystemTray tray = SystemTray.getSystemTray();
  try
  {
    tray.add(icon);
  }
  catch (AWTException e)
  {
    throw new UnavailableException(L.m("System Tray ist nicht verfügbar!"), e);
  }
}
 
開發者ID:WollMux,項目名稱:WollMux,代碼行數:26,代碼來源:WollMuxBarTrayIcon.java

示例10: setTray

import java.awt.SystemTray; //導入方法依賴的package包/類
void setTray() {
    if (!Config.getInstance().getBoolean(Config.MAIN_TRAY)) {
        this.removeTray();
        return;
    }

    if (!SystemTray.isSupported()) {
        LOGGER.info("tray icon not supported");
        return;
    }

    if (mTrayIcon == null)
        mTrayIcon = this.createTrayIcon();

    SystemTray tray = SystemTray.getSystemTray();
    if (tray.getTrayIcons().length > 0)
        return;

    try {
        tray.add(mTrayIcon);
    } catch (AWTException ex) {
        LOGGER.log(Level.WARNING, "can't add tray icon", ex);
    }
}
 
開發者ID:kontalk,項目名稱:desktopclient-java,代碼行數:25,代碼來源:TrayManager.java

示例11: setUpSysTray

import java.awt.SystemTray; //導入方法依賴的package包/類
private void setUpSysTray() {
	if(!SystemTray.isSupported()) {
		JOptionPane.showMessageDialog(this,
		    "Your OS doesn't support sytem tray.\n" +
		    "Lector will execute without a tray icon.",
		    Lector.APP_NAME,
		    JOptionPane.WARNING_MESSAGE);
		return;
	}
	
	SystemTray tray = SystemTray.getSystemTray();

	LectorTrayIcon trayIcon = new LectorTrayIcon();
	try {
		tray.add(trayIcon);
	} catch (AWTException e) {
		e.printStackTrace();
	}
}
 
開發者ID:Nirei,項目名稱:lector-rvsp,代碼行數:20,代碼來源:LectorWindow.java

示例12: hideToTray

import java.awt.SystemTray; //導入方法依賴的package包/類
private void hideToTray() {
  if (!isInTray) {
    SystemTray tray = SystemTray.getSystemTray();
    String iconPath = tray.getTrayIconSize().height > 16 ? TRAY_ICON : TRAY_SMALL_ICON;
    URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(iconPath);
    Image img = Toolkit.getDefaultToolkit().getImage(iconUrl);
    PopupMenu popup = makePopupMenu();
    try {
      trayIcon = new TrayIcon(img, TRAY_TOOLTIP, popup);
      trayIcon.addMouseListener(new TrayActionListener());
      setTrayIcon();
      tray.add(trayIcon);
    } catch (AWTException e1) {
      Tools.showError(e1);
    }
  }
  isInTray = true;
  frame.setVisible(false);
}
 
開發者ID:languagetool-org,項目名稱:languagetool,代碼行數:20,代碼來源:Main.java

示例13: start

import java.awt.SystemTray; //導入方法依賴的package包/類
private void start(String[] args) {
    SystemTray tray = SystemTray.getSystemTray();
    TrayIcon icon = new TrayIcon(Toolkit.getDefaultToolkit().createImage(
            getClass().getResource(
                    "/com/ramussoft/gui/server/application.png")),
            getString("Server") + " " + Metadata.getApplicationName(),
            createPopupMenu());
    icon.setImageAutoSize(true);
    try {
        tray.add(icon);
    } catch (AWTException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:15,代碼來源:Manager.java

示例14: setupTray

import java.awt.SystemTray; //導入方法依賴的package包/類
public static void setupTray() throws AWTException {
	final SystemTray tray = SystemTray.getSystemTray();
	final PopupMenu popup = new PopupMenu();
	final MenuItem info = new MenuItem();
	final MenuItem exit = new MenuItem();
	final TrayIcon trayIcon = new TrayIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), "MLGA", popup);
	try {
		InputStream is = FileUtil.localResource("icon.png");
		trayIcon.setImage(ImageIO.read(is));
		is.close();
	} catch (IOException e1) {
		e1.printStackTrace();
	}

	info.addActionListener(e -> {
		String message = "Double-Click to lock/unlock the overlay for dragging";
		JOptionPane.showMessageDialog(null, message, "Information", JOptionPane.INFORMATION_MESSAGE);
	});

	exit.addActionListener(e -> {
		running = false;
		tray.remove(trayIcon);
		ui.close();
		System.out.println("Terminated UI...");
		System.out.println("Cleaning up system resources. Could take a while...");
		handle.close();
		System.out.println("Killed handle.");
		System.exit(0);
	});
	info.setLabel("Help");
	exit.setLabel("Exit");
	popup.add(info);
	popup.add(exit);
	tray.add(trayIcon);
}
 
開發者ID:PsiLupan,項目名稱:MakeLobbiesGreatAgain,代碼行數:36,代碼來源:Boot.java

示例15: setupTrayIcon

import java.awt.SystemTray; //導入方法依賴的package包/類
private TrayIcon setupTrayIcon()
{
	if (!SystemTray.isSupported())
	{
		return null;
	}

	SystemTray systemTray = SystemTray.getSystemTray();
	TrayIcon trayIcon = new TrayIcon(ICON, properties.getTitle());
	trayIcon.setImageAutoSize(true);

	try
	{
		systemTray.add(trayIcon);
	}
	catch (AWTException ex)
	{
		log.debug("Unable to add system tray icon", ex);
		return trayIcon;
	}

	// bring to front when tray icon is clicked
	trayIcon.addMouseListener(new MouseAdapter()
	{
		@Override
		public void mouseClicked(MouseEvent e)
		{
			setVisible(true);
			setState(Frame.NORMAL); // unminimize
		}
	});

	return trayIcon;
}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:35,代碼來源:ClientUI.java


注:本文中的java.awt.SystemTray.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。