Java Code Examples for java.awt.TrayIcon#setImageAutoSize()
The following examples show how to use
java.awt.TrayIcon#setImageAutoSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysTray.java From visualvm with GNU General Public License v2.0 | 6 votes |
private TrayIcon createTrayIcon() { Image image = createTrayImage(); String tooltip = createTrayTooltip(); trayPopup = createTrayPopup(); TrayIcon icon = new TrayIcon(image, tooltip, trayPopup); icon.setImageAutoSize(true); icon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (trayPopup.isEnabled()) toggleWindowVisibility(); } }); } }); return icon; }
Example 2
Source File: Manager.java From ramus with GNU General Public License v3.0 | 5 votes |
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(); } }
Example 3
Source File: UpdatePopupMenu.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void createSystemTrayIcons() { final TrayIcon trayIcon = new TrayIcon(createSystemTrayIconImage()); trayIcon.setImageAutoSize(true); trayIcon.setToolTip("Update Popup Menu items"); try { trayIcon.setPopupMenu(createPopupMenu(trayIcon, 2)); SystemTray.getSystemTray().add(trayIcon); } catch (AWTException ex) { throw new RuntimeException("System Tray cration failed"); } }
Example 4
Source File: PopupMenuLeakTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void createSystemTrayIcon() { final TrayIcon trayIcon = new TrayIcon(createTrayIconImage()); trayIcon.setImageAutoSize(true); try { // Add tray icon to system tray *before* adding popup menu to demonstrate buggy behaviour trayIcon.setPopupMenu(createTrayIconPopupMenu()); SystemTray.getSystemTray().add(trayIcon); iconWeakReference.set(new WeakReference<>(trayIcon)); popupWeakReference.set(new WeakReference<>(trayIcon.getPopupMenu())); } catch (final AWTException awte) { awte.printStackTrace(); } }
Example 5
Source File: SwingUtil.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
/** * Create tray icon. * * @param icon the icon * @param title the title * @param frame the frame * @return the tray icon */ @Nullable public static TrayIcon createTrayIcon(@Nonnull final Image icon, @Nonnull final String title, @Nonnull final Frame frame) { if (!SystemTray.isSupported()) { return null; } final SystemTray systemTray = SystemTray.getSystemTray(); final TrayIcon trayIcon = new TrayIcon(icon, title); 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) { frame.setVisible(true); frame.setState(Frame.NORMAL); // Restore } }); return trayIcon; }
Example 6
Source File: AlertMaker.java From Library-Assistant with Apache License 2.0 | 5 votes |
public static void showTrayMessage(String title, String message) { try { SystemTray tray = SystemTray.getSystemTray(); BufferedImage image = ImageIO.read(AlertMaker.class.getResource(LibraryAssistantUtil.ICON_IMAGE_LOC)); TrayIcon trayIcon = new TrayIcon(image, "Library Assistant"); trayIcon.setImageAutoSize(true); trayIcon.setToolTip("Library Assistant"); tray.add(trayIcon); trayIcon.displayMessage(title, message, MessageType.INFO); tray.remove(trayIcon); } catch (Exception exp) { exp.printStackTrace(); } }
Example 7
Source File: JSystemTray.java From PeerWasp with MIT License | 5 votes |
private TrayIcon create(Image image) throws IOException { TrayIcon trayIcon = new java.awt.TrayIcon(image); trayIcon.setImageAutoSize(true); trayIcon.setToolTip(tooltip); trayIcon.setPopupMenu(createMenu(false)); return trayIcon; }
Example 8
Source File: POELevelFx.java From Path-of-Leveling with MIT License | 4 votes |
private void addTrayIcon() throws AWTException { final TrayIcon trayIcon = new TrayIcon(new ImageIcon(getClass().getResource("/icons/The_Explorer_card_art.png")).getImage(), "Path of Leveling"); // Create a pop-up menu components final PopupMenu popup = new PopupMenu(); final MenuItem shutdownItem = new MenuItem("Exit"); final MenuItem settingsItem = new MenuItem("Settings"); //Add components to pop-up menu popup.add(settingsItem); popup.add(shutdownItem); trayIcon.setPopupMenu(popup); trayIcon.setImageAutoSize(true); //So the icon auto-sizes SystemTray.getSystemTray().add(trayIcon); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getButton() == java.awt.event.MouseEvent.BUTTON1) { //Left click on tray icon (single click !) Platform.runLater(() -> { //code to show things... }); } } }); shutdownItem.addActionListener(evnt -> { //code to exit the program //save stuff if(saveBuildsToMemory()){ System.out.println("Successfully saved checkpoint"); }else{ System.out.println("Checkpoint save failed"); } try { GlobalScreen.unregisterNativeHook(); } catch (NativeHookException e1) { e1.printStackTrace(); } System.exit(20); }); settingsItem.addActionListener(evnt -> { //code to exit the program //save stuff if(controller!=null){ controller.settings_event(); } }); }
Example 9
Source File: MainFrame.java From scelight with Apache License 2.0 | 4 votes |
/** * Installs a system tray icon. */ private void installTrayIcon() { if ( !SystemTray.isSupported() ) return; final TrayIcon trayIcon = new TrayIcon( Icons.MY_APP_ICON.get().getImage(), Consts.APP_NAME_FULL + " is running." ); trayIcon.setImageAutoSize( true ); try { SystemTray.getSystemTray().add( trayIcon ); this.trayIcon = trayIcon; trayIcon.addActionListener( Actions.SHOW_MAIN_FRAME ); final PopupMenu popup = new PopupMenu(); final MenuItem restoreMenuItem = new MenuItem( "Show Main Window" ); restoreMenuItem.addActionListener( Actions.SHOW_MAIN_FRAME ); popup.add( restoreMenuItem ); final MenuItem hideMenuItem = new MenuItem( "Hide Main Window" ); hideMenuItem.addActionListener( Actions.MINIMIZE_TO_TRAY ); popup.add( hideMenuItem ); popup.addSeparator(); final MenuItem restoreDefPosMenuItem = new MenuItem( "Restore Main Window to defaults" ); restoreDefPosMenuItem.addActionListener( new ActionAdapter() { @Override public void actionPerformed( final ActionEvent e ) { // First ensure it's visible and active: Actions.SHOW_MAIN_FRAME.actionPerformed( null ); // And the default position: Actions.RESTORE_DEF_WIN_POSITION.actionPerformed( null ); } } ); popup.add( restoreDefPosMenuItem ); popup.addSeparator(); final MenuItem exitMenuItem = new MenuItem( "Exit" ); exitMenuItem.addActionListener( Actions.EXIT ); popup.add( exitMenuItem ); trayIcon.setPopupMenu( popup ); Actions.MINIMIZE_TO_TRAY.setEnabled( true ); } catch ( final AWTException ae ) { Env.LOGGER.debug( "Failed to install tray icon!", ae ); } }