本文整理了Java中java.awt.TrayIcon
类的一些代码示例,展示了TrayIcon
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TrayIcon
类的具体详情如下:
包路径:java.awt.TrayIcon
类名称:TrayIcon
暂无
代码示例来源:origin: stackoverflow.com
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
PopupMenu popup = new PopupMenu();
MenuItem showItem = new MenuItem("Show");
showItem.addActionListener(showListener);
popup.add(showItem);
MenuItem closeItem = new MenuItem("Close");
closeItem.addActionListener(closeListener);
popup.add(closeItem);
trayIcon = new TrayIcon(image, "Title", popup);
trayIcon.addActionListener(showListener);
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
trayIcon.displayMessage("Some message.",
"Some other message.",
TrayIcon.MessageType.INFO);
代码示例来源:origin: igniterealtime/Openfire
tray = SystemTray.getSystemTray();
splash = new ImageIcon(getClass().getClassLoader().getResource("splash.gif"));
splashLabel = new JLabel("", splash, JLabel.CENTER);
onIcon = new ImageIcon(getClass().getClassLoader().getResource("openfire_on-16x16.gif"));
offIcon = new ImageIcon(getClass().getClassLoader().getResource("openfire_off-16x16.gif"));
frame.setIconImage(offIcon.getImage());
PopupMenu menu = new PopupMenu(appName + " Menu");
final MenuItem showMenuItem = new MenuItem("Hide");
showMenuItem.setActionCommand("Hide/Show");
menu.add(showMenuItem);
final MenuItem stopMenuItem = new MenuItem("Stop");
trayIcon = new TrayIcon(offIcon.getImage(), appName, menu);
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
tray.add(trayIcon);
代码示例来源:origin: RipMeApp/ripme
JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE,
new ImageIcon(mainIcon));
if (response == JOptionPane.YES_OPTION) {
try {
configClipboardAutorip.setSelected(trayMenuAutorip.getState());
});
trayMenu.add(trayMenuMain);
trayMenu.add(trayMenuAbout);
trayMenu.addSeparator();
trayMenu.add(trayMenuAutorip);
try {
mainIcon = ImageIO.read(getClass().getClassLoader().getResource("icon.png"));
trayIcon = new TrayIcon(mainIcon);
trayIcon.setToolTip(mainFrame.getTitle());
trayIcon.setImageAutoSize(true);
trayIcon.setPopupMenu(trayMenu);
SystemTray.getSystemTray().add(trayIcon);
trayIcon.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
代码示例来源:origin: stackoverflow.com
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem(...);
defaultItem.addActionListener(listener);
popup.add(defaultItem);
trayIcon.addActionListener(listener);
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
trayIcon.setImage(updatedImage);
代码示例来源:origin: runelite/runelite
public static TrayIcon createTrayIcon(@Nonnull final Image icon, @Nonnull final String title, @Nonnull final Frame frame)
if (!SystemTray.isSupported())
final SystemTray systemTray = SystemTray.getSystemTray();
final TrayIcon trayIcon = new TrayIcon(icon, title);
trayIcon.setImageAutoSize(true);
systemTray.add(trayIcon);
trayIcon.addMouseListener(new MouseAdapter()
代码示例来源:origin: org.nuiton.web/nuiton-web
if (SystemTray.isSupported()) {
PopupMenu menu = new PopupMenu();
MenuItem browserItem = new MenuItem("Start browser");
browserItem.addActionListener(this);
browserItem.setActionCommand("browser");
menu.add(browserItem);
MenuItem stopItem = new MenuItem("Stop server");
stopItem.addActionListener(this);
stopItem.setActionCommand("stop");
menu.add(stopItem);
System.out.println("No favicon.{png|jpg} found, skip systray installation");
} else {
Image image = new ImageIcon(imageURL).getImage();
TrayIcon icon = new TrayIcon(image, serverName, menu);
icon.setImageAutoSize(true);
icon.addMouseListener(this);
SystemTray systemTray = SystemTray.getSystemTray();
try {
systemTray.add(icon);
} catch (AWTException ex) {
throw new RuntimeException("Can't install tray icon", ex);
代码示例来源:origin: scruel/ClipIt
private static void addTray(GlobalHotkeyListener hotkeyListener) throws AWTException {
ImageIcon imageIcon = new ImageIcon(Objects.requireNonNull(TipsFrame.class.getClassLoader().getResource("ClipIt.png")));
TrayIcon trayIcon = new TrayIcon(imageIcon.getImage());
trayIcon.setToolTip("ClipIt");
PopupMenu popupMenu = new PopupMenu();
MenuItem exitMenuItem = new MenuItem("Exit");
exitMenuItem.addActionListener(actionEvent -> hotkeyListener.destroy());
popupMenu.add(exitMenuItem);
trayIcon.setPopupMenu(popupMenu);
SystemTray systemTray = SystemTray.getSystemTray();
systemTray.add(trayIcon);
}
代码示例来源:origin: aterai/java-swing-tips
public MainPanel() {
super();
setPreferredSize(new Dimension(320, 240));
if (!SystemTray.isSupported()) {
throw new UnsupportedOperationException("SystemTray is not supported");
}
Class<?> clz = MainPanel.class;
imglist[0] = new ImageIcon(clz.getResource("16x16.png")).getImage();
imglist[1] = new ImageIcon(clz.getResource("16x16l.png")).getImage();
imglist[2] = imglist[0];
imglist[3] = new ImageIcon(clz.getResource("16x16r.png")).getImage();
dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
dialog.setSize(new Dimension(120, 100));
dialog.setLocationRelativeTo(null);
dialog.setTitle("TEST: JDialog");
// TEST: icon = new TrayIcon(new ImageIcon(getClass().getResource("anime.gif")).getImage(), "TRAY", popup);
icon = new TrayIcon(imglist[0], "TRAY", makeTrayPopupMenu());
animator.addActionListener(e -> {
icon.setImage(imglist[idx]);
idx = (idx + 1) % imglist.length;
});
try {
SystemTray.getSystemTray().add(icon);
} catch (AWTException ex) {
throw new IllegalStateException(ex);
}
}
代码示例来源:origin: igniterealtime/Spark
@Override
public void connectionClosedOnError(Exception arg0) {
trayIcon.setImage(offlineIcon.getImage());
}
});
代码示例来源:origin: magefree/mage
public void install() {
if (!SystemTray.isSupported()) {
log.warn("SystemTray is not supported");
return;
mainImage = ImageManagerImpl.instance.getAppSmallImage();
flashedImage = ImageManagerImpl.instance.getAppFlashedImage();
trayIcon = new TrayIcon(mainImage);
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(e -> {
stopBlink();
MageFrame frame = MageFrame.getInstance();
});
final SystemTray tray = SystemTray.getSystemTray();
final PopupMenu popup = new PopupMenu();
exitItem.addActionListener(e -> MageFrame.getInstance().exitApp());
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
tray.add(trayIcon);
} catch (AWTException e) {
log.error("TrayIcon could not be added: ", e);
代码示例来源:origin: stackoverflow.com
if (e.getNewState() == ICONIFIED) {
try {
final TrayIcon trayIcon = new TrayIcon(new ImageIcon("/usr/share/icons/gnome/16x16/emotes/face-plain.png").getImage());
trayIcon.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
代码示例来源:origin: stackoverflow.com
tray = SystemTray.getSystemTray();
PropertyChangeListener propListener = new PropertyChangeListener() {
tray.addPropertyChangeListener("trayIcons", propListener);
icon = new BevelArrowIcon(BevelArrowIcon.UP, false, false);
image = iconToImage(icon);
icon1 = new BevelArrowIcon(BevelArrowIcon.DOWN, false, false);
image1 = iconToImage(icon1);
PopupMenu popup = new PopupMenu();
MenuItem item = new MenuItem("Hello, World");
trayIcon = new TrayIcon(image, "Tip Text", popup);
ActionListener menuActionListener = new ActionListener() {
trayIcon.displayMessage("Good-bye", "Cruel World",
TrayIcon.MessageType.WARNING);
trayIcon.addActionListener(actionListener);
timer = new javax.swing.Timer(125, updateCol());
timer.start();
trayIcon.displayMessage(null, " Aplication Loaded ", TrayIcon.MessageType.NONE);
Image img = trayIcon.getImage();
if (img == image) {
trayIcon.setImage(image1);
} else {
trayIcon.setImage(image);
代码示例来源:origin: mil.army.missioncommand/mil-sym-renderer
isSysTraySupported();
String toolTip = "SEC MilStd 2525 Rendering Service";
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(createImage("images/globe.png", toolTip),toolTip);
final SystemTray sysTray = SystemTray.getSystemTray();
Menu displayMenu = new Menu("Display");
MenuItem aboutItem = new MenuItem("About");
MenuItem exitItem = new MenuItem("Exit");
popup.add(aboutItem);
popup.addSeparator();
popup.addSeparator();
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
trayIcon.displayMessage("caption", "text", TrayIcon.MessageType.ERROR);
sysTray.add(trayIcon);
trayIcon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
aboutItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
代码示例来源:origin: igniterealtime/Openfire
startMenuItem.setEnabled(false);
stopMenuItem.setEnabled(true);
frame.setIconImage(onIcon.getImage());
trayIcon.setImage(onIcon.getImage());
stopApplication();
frame.setIconImage(offIcon.getImage());
trayIcon.setImage(offIcon.getImage());
startButton.setEnabled(true);
stopButton.setEnabled(false);
browserMenuItem.setEnabled(false);
startMenuItem.setEnabled(true);
stopMenuItem.setEnabled(false);
代码示例来源:origin: stackoverflow.com
return;
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon =
new TrayIcon(createImage("images/bulb.gif", "tray icon"));
MenuItem aboutItem = new MenuItem("About");
CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
Menu displayMenu = new Menu("Display");
MenuItem errorItem = new MenuItem("Error");
MenuItem warningItem = new MenuItem("Warning");
MenuItem infoItem = new MenuItem("Info");
MenuItem noneItem = new MenuItem("None");
trayIcon.setPopupMenu(popup);
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
代码示例来源:origin: SKCraft/Launcher
private boolean setupTrayIcon() {
if (!SystemTray.isSupported()) {
return false;
trayIcon = new TrayIcon(getTrayRunningIcon());
trayIcon.setImageAutoSize(true);
trayIcon.setToolTip(SharedLocale.tr("console.trayTooltip"));
trayIcon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PopupMenu popup = new PopupMenu();
MenuItem item;
popup.add(item = new MenuItem(SharedLocale.tr("console.trayTitle")));
item.setEnabled(false);
popup.add(item = new MenuItem(SharedLocale.tr("console.tray.showWindow")));
item.addActionListener(new ActionListener() {
@Override
trayIcon.setPopupMenu(popup);
SystemTray tray = SystemTray.getSystemTray();
tray.add(trayIcon);
return true;
} catch (AWTException e) {
代码示例来源:origin: stackoverflow.com
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon.displayMessage("Action Event",
"An Action Event Has Been Performed!",
TrayIcon.MessageType.INFO);
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(mouseListener);
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
代码示例来源:origin: stackoverflow.com
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().createImage(new URL("http://docs.oracle.com/javase/tutorial/uiswing/examples/misc/TrayIconDemoProject/src/misc/images/bulb.gif")));
trayIcon.setToolTip("I am the initial message");
final SystemTray tray = SystemTray.getSystemTray();
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
trayIcon.setToolTip("I am the last message");
trayIcon.setToolTip("I am the second message");
trayIcon.setToolTip("I am the first message");
代码示例来源:origin: xXKeyleXx/MyPet
private static void createTraymenu(Image logoImage) {
trayIcon = new TrayIcon(logoImage);
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(e -> {
close();
});
MenuItem reopenItem = new MenuItem("Reopen");
reopenItem.addActionListener(e -> {
try {
Desktop.getDesktop().browse(new URI("http://localhost:64712"));
} catch (URISyntaxException | IOException e2) {
e2.printStackTrace();
}
});
PopupMenu popup = new PopupMenu();
popup.add(reopenItem);
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
trayIcon.setToolTip("MyPet - SkilltreeCreator");
try {
SystemTray.getSystemTray().add(trayIcon);
} catch (AWTException e) {
e.printStackTrace();
}
trayIcon.displayMessage("MyPet - SkilltreeCreator", "The SkilltreeCreator is running. You can exit it via the tray icon.", TrayIcon.MessageType.INFO);
}
代码示例来源:origin: stackoverflow.com
frame.setUndecorated(true);
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
final TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(
new URL("http://home.comcast.net/~supportcd/Icons/Java_Required.jpg")), "Library Drop");
final SystemTray tray = SystemTray.getSystemTray();
trayIcon.setPopupMenu(popup);
trayIcon.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
frame.add(popup);
popup.show(frame, e.getXOnScreen(), e.getYOnScreen());
frame.setResizable(false);
frame.setVisible(true);
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
popup.add(aboutItem);
popup.addSeparator();
内容来源于网络,如有侵权,请联系作者删除!