本文整理匯總了Java中java.awt.SystemTray.getSystemTray方法的典型用法代碼示例。如果您正苦於以下問題:Java SystemTray.getSystemTray方法的具體用法?Java SystemTray.getSystemTray怎麽用?Java SystemTray.getSystemTray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.SystemTray
的用法示例。
在下文中一共展示了SystemTray.getSystemTray方法的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);
}
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例5: Tray
import java.awt.SystemTray; //導入方法依賴的package包/類
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);
}
示例6: 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);
}
示例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) {
// 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();
}
}
示例8: 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();
}
}
示例9: 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);
}
}
}
}
示例10: 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);
}
}
示例11: 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);
}
}
示例12: 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();
}
}
示例13: GuruztrayManagerImplementation
import java.awt.SystemTray; //導入方法依賴的package包/類
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);
}
示例14: JfxTrayIcon
import java.awt.SystemTray; //導入方法依賴的package包/類
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();
}
});
}
}
示例15: 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);
}