本文整理匯總了Java中java.awt.TrayIcon.setPopupMenu方法的典型用法代碼示例。如果您正苦於以下問題:Java TrayIcon.setPopupMenu方法的具體用法?Java TrayIcon.setPopupMenu怎麽用?Java TrayIcon.setPopupMenu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.TrayIcon
的用法示例。
在下文中一共展示了TrayIcon.setPopupMenu方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSystemTrayIcons
import java.awt.TrayIcon; //導入方法依賴的package包/類
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");
}
}
示例2: createSystemTrayIcon
import java.awt.TrayIcon; //導入方法依賴的package包/類
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();
}
}
示例3: initTray
import java.awt.TrayIcon; //導入方法依賴的package包/類
private void initTray() {
// get the system tray
SystemTray systemTray = SystemTray.getSystemTray();
// create a "hidden" frame for the popup menu
final Frame frame = new Frame("");
frame.setUndecorated(true);
try {
// instance the icon
BufferedImage icon = ImageIO.read(SimpleUI.class.getResource("/icon_16x16x32.png"));
final TrayIcon trayIcon = new TrayIcon(new ImageIcon(icon).getImage(), Main.getString("msg.systemtray"));
trayIcon.setImageAutoSize(true); // Autosize icon base on space available on tray
final PopupMenu menu = createPopupMenu();
trayIcon.setPopupMenu(menu);
trayIcon.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
System.out.println("icon clicked: " + evt.getClickCount());
// dont display the menu if the screen selection ui (this jframe) is showing
if (!isVisible()) {
frame.setVisible(true);
frame.add(menu);
menu.show(frame, evt.getXOnScreen(), evt.getYOnScreen());
}
}
});
frame.setResizable(false);
systemTray.add(trayIcon);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: initSysTray
import java.awt.TrayIcon; //導入方法依賴的package包/類
private void initSysTray()
{
stage.getIcons().addAll(Main.appIconList);
java.awt.Image image = Toolkit.getDefaultToolkit().getImage(Main.class.getResource(Main.iconResource16));
Platform.setImplicitExit(false); //needed to keep the app running while minimized to tray
trayIcon = new TrayIcon(image, Main.appTitle);
Runnable restoreApplication = () ->
{
stage.show();
SystemTray.getSystemTray().remove(trayIcon);
};
trayIcon.addActionListener(ae -> Platform.runLater(restoreApplication));
java.awt.PopupMenu popupMenu = new PopupMenu();
java.awt.MenuItem restore = new java.awt.MenuItem("Restore");
restore.addActionListener(al -> Platform.runLater(restoreApplication));
popupMenu.add(restore);
java.awt.MenuItem exit = new java.awt.MenuItem("Exit");
exit.addActionListener(al -> exitRequestedByUser());
popupMenu.addSeparator();
popupMenu.add(exit);
trayIcon.setPopupMenu(popupMenu);
}
示例5: create
import java.awt.TrayIcon; //導入方法依賴的package包/類
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;
}
示例6: App
import java.awt.TrayIcon; //導入方法依賴的package包/類
public App() throws AWTException, IOException
{
if (!SystemTray.isSupported())
throw new UnsupportedOperationException("No system tray!");
BufferedImage icon = loadImage("icons/lightbulb16.png");
trayIcon = new TrayIcon(icon, "Monitor Brightness Adjuster");
trayIcon.setImageAutoSize(true);
SystemTray.getSystemTray().add(trayIcon);
trayIcon.setPopupMenu(createPopup());
}
示例7: setTrayIcon
import java.awt.TrayIcon; //導入方法依賴的package包/類
public void setTrayIcon(Image i_16x16, Image i_22x22, String tt, PopupMenu pm) throws Exception {
boolean autoSize = false;
Image i = null;
Dimension d = tray.getTrayIconSize();
if (d.height == 16 && d.width == 16)
{
i = i_16x16;
//System.out.println ("Tray 16x16 picked");
autoSize = true;
}
else
{
i = i_22x22;
//System.out.println ("Tray 22x22 picked");
autoSize = true;
}
trayIcon = new TrayIcon (i, tt);
trayIcon.addMouseListener(this);
trayIcon.setImageAutoSize(autoSize);
if (pm != null)
trayIcon.setPopupMenu(pm);
tray.add(trayIcon);
//System.out.println ("Tray real width=" + trayIcon.getSize().width + " height=" + trayIcon.getSize().height);
}
示例8: installTrayIcon
import java.awt.TrayIcon; //導入方法依賴的package包/類
/**
* 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 );
}
}
示例9: SystemTrayHandler
import java.awt.TrayIcon; //導入方法依賴的package包/類
public SystemTrayHandler(PluginHandler plugin, String working_directory, AudioInput in)
{
this.plugin = plugin;
this.in = in;
this.plugins_directory = working_directory + "Plugins/";
// Okay, this one was stupid hacky. I couldn't figure out how to export
// images with processing, but I noticed that in
// Processing.app/Contents/Java/ there was a file named jssc.txt.
// I'm almost 100% certain that Processing isn't using this. So I found
// the file in /Applications/Processing.app/Contents/Java/modes/java/libraries/serial/library/jssc.txt
// I took my icon.gif and renamed it to jssc.txt, and it appears to work.
String icon = SystemTrayHandler.class.getResource("").getPath() + "jssc.txt";
if ( SystemTray.isSupported() )
{
if ( !( new File( icon ) ).exists() )
{
String local_icon = working_directory + "icon.gif";
if ( !( new File( local_icon ) ).exists() )
{
Message.showError(
"Could not find icon.gif to put in the System Tray. We looked in<br />"+
icon +
"<br />and<br />" +
local_icon +
"<br /><br />The program will now exit.",
"ICON_NOT_FOUND" );
System.exit(1);
}
icon = local_icon;
}
final PopupMenu popup = new PopupMenu();
final Image image = Toolkit.getDefaultToolkit()
.getImage( icon );
final TrayIcon trayIcon = new TrayIcon( image, "Light Controller" );
final SystemTray tray = SystemTray.getSystemTray();
addPluginsMenu( popup );
popup.addSeparator();
if(!MIXER_BUG) addAudioMenu( popup );
addSettingsMenu( popup );
popup.addSeparator();
addExitItem( popup );
trayIcon.setPopupMenu( popup );
try
{
tray.add( trayIcon );
}
catch ( AWTException e )
{
Message.showError(
"There was a problem creating an icon on the system tray.<br />"+
"The program will now exit.<br />"+
"Below you will find the stack trace for this error.\n",
"AWTException_CREATING_ICON", e );
System.exit(1);
}
}
else
{
Message.showError(
"Light Controller is not supported on this machine<br />"+
"due to system tray being unsupported.<br />"+
"The program will now exit.", "NO_SYS_TRAY" );
System.exit(1);
}
}
示例10: build
import java.awt.TrayIcon; //導入方法依賴的package包/類
/**
* Builds a tray icon from the parameters contained in the
* current instance's Configuration object.
* @param instance An instance of Skope.
* @return The TrayIcon object that was created and added to
* the tray.
*/
public static TrayIcon build(final Main instance) {
// if the system doesn't support system trays
if(!SystemTray.isSupported())
return null;
// get the image icon for the tray
Image icon = null;
icon = instance.getBuilder().getIconImage();
// build TrayIcon
final TrayIcon trayIcon = new TrayIcon(icon);
// create pop up menu for tray icon
final PopupMenu popupMenu = new PopupMenu();
popupMenu.add("About");
popupMenu.add("Activate/Deactivate");
popupMenu.add("Settings");
popupMenu.add("Exit");
popupMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if(event.getActionCommand().equals("About")) {
popupMenu.setEnabled(false);
AboutDialog.displayAboutBox(null, instance);
popupMenu.setEnabled(true);
} else if(event.getActionCommand().equals("Exit")) {
popupMenu.setEnabled(false);
if(instance.getSecurity().auditPasswordDialog(null, instance.getBuilder()))
instance.terminate();
} else if(event.getActionCommand().equals("Activate/Deactivate")) {
popupMenu.setEnabled(false);
if(instance.getSecurity().auditPasswordDialog(null, instance.getBuilder())) {
if(instance.getService().isEnabled()) {
instance.stopService();
} else {
instance.startService();
}
}
popupMenu.setEnabled(true);
} else if (event.getActionCommand().equals("Settings")) {
popupMenu.setEnabled(false);
instance.launchUI();
popupMenu.setEnabled(true);
}
}
});
trayIcon.setPopupMenu(popupMenu);
trayIcon.setImageAutoSize(true);
// add icon to the tray
try {
SystemTray.getSystemTray().add(trayIcon);
} catch (AWTException e) {
return null;
}
return trayIcon;
}