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); } } }
/** * 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); } }
public static void main(String[] args) { Util.setNativeLookAndFeel(); SwingUtilities.invokeLater(new Runnable() { public void run() { // Check the SystemTray is supported if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); System.exit(0); } else { new Dropzone(); } } }); }
@Override protected void processEvent(InboxChangeEvent event) throws IOException { // TODO Auto-generated method stub if (SystemTray.isSupported()) { if(event.getUnreadItemCount() > 0) { trayIcon.setImage(this.imageNewMail); } else { trayIcon.setImage(this.imageNoMail); } if(OwaNotifier.getInstance().getProps().getProperty("notification.type").contentEquals("system")) { trayIcon.displayMessage(event.getEventTitle(), event.getEventText(), MessageType.INFO); } } else { logger.error("System tray not supported!"); } if(event.getUnreadItemCount() > 0) { this.setToolTip(event.getUnreadItemCount() + " message(s) non lu"); } else { this.setToolTip("Pas de message non lu"); } }
/** Add tray icon to system tray */ public void addTrayIconInSystemTray() { if (SystemTray.isSupported()) { setEventListener(); setMenu(); try { trayIcon.setImageAutoSize(true); trayIcon.addActionListener(showListener); trayIcon.addMouseListener(mouseListener); systemTray.add(trayIcon); } catch (AWTException e) { e.printStackTrace(); } } else { System.err.println("Tray unavailable"); } }
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { System.out.println("SystemTray not supported on the platform." + " Marking the test passed."); } else { if (System.getProperty("os.name").toLowerCase().startsWith("win")) { System.err.println( "Test can fail on Windows platform\n"+ "On Windows 7, by default icon hides behind icon pool\n" + "Due to which test might fail\n" + "Set \"Right mouse click\" -> " + "\"Customize notification icons\" -> \"Always show " + "all icons and notifications on the taskbar\" true " + "to avoid this problem.\nOR change behavior only for " + "Java SE tray icon and rerun test."); } ActionEventTest test = new ActionEventTest(); test.doTest(); test.clear(); } }
private void initializeGUI() { icon = new TrayIcon( new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "ti"); icon.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { actionPerformed = true; int md = ae.getModifiers(); int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK; if ((md & expectedMask) != expectedMask) { clear(); throw new RuntimeException("Action Event modifiers are not" + " set correctly."); } } }); try { SystemTray.getSystemTray().add(icon); } catch (Exception e) { throw new RuntimeException(e); } }
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { System.out.println("SystemTray not supported on the platform " + "under test. Marking the test passed"); } else { String osName = System.getProperty("os.name").toLowerCase(); if (osName.startsWith("mac")) { isMacOS = true; } else if (osName.startsWith("win")) { isWinOS = true; } else { isOelOS = SystemTrayIconHelper.isOel7(); } new TrayIconMouseTest().doTest(); } }
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(); } }
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing if (trayIcon != null) { SystemTray.getSystemTray().remove(trayIcon); } if (mCurrentAudioMonitor != null) { mCurrentAudioMonitor.stopMonitoring(); mCurrentAudioMonitor = null; } if (mRemote != null) { mRemote.shutdown(); mRemote = null; } if (mShortcuts != null) { mShortcuts.stop(); } }
/** * 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); }
public Tray(MainWindow window) { if (tray != null) return; if (!SystemTray.isSupported()) { System.err.println("系统不支持托盘!"); } if (tray == null) { tray = SystemTray.getSystemTray(); } if (window == null) throw new NullPointerException(); this.window = window; try { setTray(); } catch (Exception e) { e.printStackTrace(); } addIcon(); // window.setVisible(false); }
/** * @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); }
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(); } }
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(); } }
public void setXBtnBehavior(boolean minimize) { if (!minimize) stage.setOnCloseRequest(we -> exitRequestedByUser()); else if (!SystemTray.isSupported()) logger.log(Level.WARNING, "Minimize to tray is not supported."); else { stage.setOnCloseRequest(we -> { we.consume(); //ignore the application's title window exit button, instead minimize to systray minimizeRequestCameFromXBtn = true; performMinimizeToTray.run(); }); } menuItemChkDisplayBalloon.setDisable(!minimize); }
/** * 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); } } } }
private void hookTray() { if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); } else { try { Todo.icon = new TrayIcon(ImageIO.read(Todo.class.getResourceAsStream("/todo/res/logoTray.png")), "TODO application", createPopupMenu()); Todo.icon.addActionListener((ActionEvent e) -> { Platform.runLater(() -> { stage.setIconified(false); }); //some popup test }); SystemTray.getSystemTray().add(Todo.icon); //Thread.sleep(3000); Todo.icon.displayMessage("TODO", "Listener enabled", TrayIcon.MessageType.INFO); } catch (AWTException | IOException ex) { ex.printStackTrace(); } } }
/** * Displays a message at the system tray * * @param caption * @param text * @param messageType * @param listener */ public static void displayMessage(String caption, String text, MessageType messageType, ActionListener listener) { log.info(messageType + ": " + text); if (SystemTray.isSupported()) { removeAllListeners(); if (listener != null) { getTrayIcon().addActionListener(listener); } getTrayIcon().displayMessage(caption, text, messageType); } }
/** * Start next upload if any.. Decrements the current uploads averageProgress and * updates the queuing mechanism. */ public void startNextUploadIfAny() { currentlyUploading--; //If no more uploads in queue and no more uploads currently running, reset the title if (getQueuedUploadCount() == 0 && currentlyUploading == 0){ setFrameTitle(); try{ //If the tray icon is activated, then display message if(SystemTray.getSystemTray().getTrayIcons().length > 0) { SystemTray.getSystemTray().getTrayIcons()[0].displayMessage(Translation.T().neembuuuploader(), Translation.T().allUploadsCompleted(), TrayIcon.MessageType.INFO); } }catch(UnsupportedOperationException a){ //ignore } } else { updateQueue(); } }
private void setUpTrayIcon() { if (SystemTray.isSupported()) { //trayIcon.setImageAutoSize(true); It renders the icon very poorly. //So we render the icon ourselves with smooth settings. { Dimension d = SystemTray.getSystemTray().getTrayIconSize(); trayIcon = new TrayIcon(getIconImage().getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH)); } //trayIcon = new TrayIcon(getIconImage()); //trayIcon.setImageAutoSize(true); trayIcon.setToolTip(Translation.T().trayIconToolTip()); trayIcon.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NULogger.getLogger().info("System tray double clicked"); setExtendedState(JFrame.NORMAL); setVisible(true); repaint(); SystemTray.getSystemTray().remove(trayIcon); } }); } }
private void switchVisibility() { if (!SystemTray.isSupported()) { return; } if (!Boolean.TRUE.equals(this.systrayAction.getValue())) { return; } boolean v = !this.frame.isVisible(); this.frame.setVisible(v); if (v) { this.frame.toFront(); this.frame.setState(Frame.NORMAL); } if (!v) { try { SystemTray.getSystemTray().add(this.trayIcon); } catch (AWTException ex) { HqlBuilderFrame.logger.error("{}", ex); } } else { SystemTray.getSystemTray().remove(this.trayIcon); } }
private IconeTaches() { super(Images.get("divers/icone.png", true), TITRE); setImageAutoSize(true); setPopupMenu(menu = new PopupMenu("Menu")); menu.add(quitter = new MenuItem("Quitter")); menu.add(infos = new MenuItem("A propos...")); menu.add(admin = new MenuItem("Administrer")); menu.addSeparator(); menu.add(d3d = new MenuItem("Dessin 3D")); menu.add(d2d = new MenuItem("Dessin 2D")); quitter.addActionListener(this); infos.addActionListener(this); admin.addActionListener(this); d3d.addActionListener(this); d2d.addActionListener(this); if(SystemTray.isSupported()) try { SystemTray.getSystemTray().add(this); } catch(AWTException e) { e.printStackTrace(); } }
private void createComponents() { PopupMenu menu = new PopupMenu(); menu.add(createMenuItem(openAction)); menu.add(createMenuItem(controlPanelAction)); menu.addSeparator(); menu.add(createMenuItem(quitAction)); URL url = getClass().getResource("/images/futuresonic-21.png"); Image image = Toolkit.getDefaultToolkit().createImage(url); TrayIcon trayIcon = new TrayIcon(image, "FutureSonic Music Streamer", menu); trayIcon.setImageAutoSize(false); try { SystemTray.getSystemTray().add(trayIcon); } catch (Throwable x) { System.err.println("Failed to add tray icon."); } }
/** * 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); } }
private void createComponents() { PopupMenu menu = new PopupMenu(); menu.add(createMenuItem(openAction)); menu.add(createMenuItem(controlPanelAction)); menu.addSeparator(); menu.add(createMenuItem(quitAction)); URL url = getClass().getResource("/images/madsonic-21.png"); Image image = Toolkit.getDefaultToolkit().createImage(url); TrayIcon trayIcon = new TrayIcon(image, "Madsonic Music Streamer", menu); trayIcon.setImageAutoSize(false); try { SystemTray.getSystemTray().add(trayIcon); } catch (Throwable x) { System.err.println("Failed to add tray icon."); } }
public void hideToTray() { if (sysTray == null || SystemTray.isSupported() == false) { System.out.println("GuiSwing::hideToTray SystemTray not supported!"); return; } try { trayIcon = getTrayIcon(); sysTray.add(trayIcon); } catch (AWTException e) { System.out.println("GuiSwing::hideToTray an error occured while trying to add system tray icon (exception: " + e + ")"); return; } setVisible(false); }
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); } }
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(); } }
@Override public void close() throws Exception { try { if (thread != null) { logger.info("Waiting for thread to terminate"); thread.join(); } } catch (InterruptedException e) { logger.warn("Thread interrupted", e); Thread.currentThread().interrupt(); } luminanceProvider.close(); SystemTray.getSystemTray().remove(trayIcon); logger.info("Finished"); }
public GuruztrayManagerImplementation () throws Exception { // workaround to disable system tray in Gnome 3 // // see following comment for an explanation // https://bugzilla.redhat.com/show_bug.cgi?id=683768#c4 // // bugreport on Oracle // JDK 7 http://bugs.java.com/bugdatabase/view_bug.do?bug_id=2217240 // JDK 8 http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7103610 // // even using JDK 1.8.0_25-b17 the system tray doesn't work // on Gnome 3.8+8 using the example code from Oracle // http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html if ("gnome".equals(System.getenv("XDG_SESSION_DESKTOP"))) { throw new Exception("System tray support has been disabled for Gnome desktop environment"); } if (!isSupported()) throw new Exception ("Tray not supported"); tray = SystemTray.getSystemTray(); Dimension d = tray.getTrayIconSize(); //System.out.println ("System Tray icon width=" + d.width + " height=" + d.height); }
private static void createAndShowGui() { JDialog dialog = createDialog(); CloseDialogListener closeDialogListener = new CloseDialogListener(dialog); dialog.addWindowFocusListener(closeDialogListener); JPopupMenu systemTrayPopupMenu = buildMenu(); systemTrayPopupMenu.addPopupMenuListener(closeDialogListener); TrayIcon trayIcon = new TrayIcon(getTrayIconImage()); trayIcon.addMouseListener(new ShowTrayMenuListener(systemTrayPopupMenu, dialog)); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { throw new IllegalStateException("Failed to add tray icon"); } }
public SysTrayIcon(JDesktopAgent frame, String tooltip) { Translate translate = Translate.getTranslate(); if (SystemTray.isSupported()) { Image image = Toolkit.getDefaultToolkit().getImage("icon.png"); PopupMenu popup = new PopupMenu(); popup.add(new RestoreMenuItem(frame, translate.backgroundRestore())); popup.addSeparator(); popup.add(new AboutMenuItem(translate.about())); popup.addSeparator(); popup.add(new ExitMenuItem(translate.exit())); TrayIcon trayIcon = new TrayIcon(image, tooltip, popup); trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new IconListener(frame)); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { new SysTrayForm(frame).setVisible(true); } } else { new SysTrayForm(frame).setVisible(true); } }
public static boolean create() { menu = new Menu(); try { icon = new TrayIcon(Constants.TRAY_ICON, "UploadR", menu); icon.addMouseListener(menu.getItemHandler()); SystemTray.getSystemTray().add(icon); icon.setToolTip("UploadR"); return true; } catch(AWTException e) { return false; } }
public JfxTrayIcon() { if (!SystemTray.isSupported()) { log.warn("system tray not supported!"); this.tray = null; } else { this.tray = SystemTray.getSystemTray(); this.menu = new PopupMenu(); this.exit = new MenuItem("Exit"); this.menu.add(exit); this.exit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { hide(); // important, otherwise AWT keeps application alive! Platform.exit(); } }); } }