本文整理了Java中java.awt.PopupMenu
类的一些代码示例,展示了PopupMenu
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PopupMenu
类的具体详情如下:
包路径:java.awt.PopupMenu
类名称:PopupMenu
暂无
代码示例来源: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();
PopupMenu menu = new PopupMenu(appName + " Menu");
final MenuItem showMenuItem = new MenuItem("Hide");
showMenuItem.setActionCommand("Hide/Show");
menu.add(showMenuItem);
final MenuItem startMenuItem = new MenuItem("Start");
startMenuItem.setActionCommand("Start");
menu.add(startMenuItem);
final MenuItem stopMenuItem = new MenuItem("Stop");
stopMenuItem.setActionCommand("Stop");
menu.add(stopMenuItem);
final MenuItem browserMenuItem = new MenuItem("Launch Admin");
browserMenuItem.setActionCommand("Launch Admin");
menu.add(browserMenuItem);
menu.addSeparator();
final MenuItem quitMenuItem = new MenuItem("Quit");
quitMenuItem.setActionCommand("Quit");
menu.add(quitMenuItem);
tray.add(trayIcon);
代码示例来源:origin: stackoverflow.com
popup.getMenuInflater().inflate(R.menu.clipboard_popup,
popup.getMenu());
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.install:
代码示例来源:origin: stackoverflow.com
public boolean onOptionsItemSelected(MenuItem item) {
// ...
View menuItemView = findViewById(R.id.menu_overflow); // SAME ID AS MENU ID
PopupMenu popupMenu = new PopupMenu(this, menuItemView);
popupMenu.inflate(R.menu.counters_overflow);
// ...
popupMenu.show();
// ...
return true;
}
代码示例来源:origin: stackoverflow.com
public void onPopupButtonClick(View button) {
PopupMenu popup = new PopupMenu(this, button);
popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(PopupMenu1.this, "Clicked popup menu item " + item.getTitle(),
Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
}
代码示例来源:origin: stackoverflow.com
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.actions, popup.getMenu());
popup.show();
}
代码示例来源:origin: stackoverflow.com
public void showPopup(View v, final int listItemPosition) {
PopupMenu popup = new PopupMenu(this, v);
popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_play:
// read the listItemPosition here
return true;
default:
return false;
}
}
});
popup.inflate(R.menu.actions);
popup.show();
}
代码示例来源:origin: stackoverflow.com
// try this way,hope this will help you...
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_options) {
PopupMenu popupMenu = new PopupMenu(this, v);
popupMenu.inflate(R.menu.settings);
popupMenu.show();
}
return super.onOptionsItemSelected(item);
}
代码示例来源: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.");
代码示例来源: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);
aboutItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
代码示例来源:origin: i2p/i2p.i2p
public PopupMenu getMainMenu() {
PopupMenu popup = new PopupMenu();
MenuItem startItem = new MenuItem(_t("Start I2P"));
startItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new SwingWorker<Object, Object>() {
@Override
protected Object doInBackground() throws Exception {
RouterManager.start();
return null;
}
@Override
protected void done() {
trayIcon.displayMessage(_t("Starting"), _t("I2P is starting!"), TrayIcon.MessageType.INFO);
//Hide the tray icon.
//We cannot stop the desktopgui program entirely,
//since that risks killing the I2P process as well.
tray.remove(trayIcon);
}
}.execute();
}
});
popup.add(startItem);
return popup;
}
代码示例来源: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: RipMeApp/ripme
public void windowIconified(WindowEvent e) { trayMenuMain.setLabel("Show"); }
});
PopupMenu trayMenu = new PopupMenu();
trayMenuMain = new MenuItem("Hide");
trayMenuMain.addActionListener(arg0 -> toggleTrayClick());
MenuItem trayMenuAbout = new MenuItem("About " + mainFrame.getTitle());
trayMenuAbout.addActionListener(arg0 -> {
StringBuilder about = new StringBuilder();
configClipboardAutorip.setSelected(trayMenuAutorip.getState());
});
trayMenu.add(trayMenuMain);
trayMenu.add(trayMenuAbout);
trayMenu.addSeparator();
trayMenu.add(trayMenuAutorip);
trayMenu.addSeparator();
trayMenu.add(trayMenuExit);
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
代码示例来源:origin: stackoverflow.com
return;
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon =
new TrayIcon(createImage("images/bulb.gif", "tray icon"));
popup.add(aboutItem);
popup.addSeparator();
popup.add(cb1);
popup.add(cb2);
popup.addSeparator();
popup.add(displayMenu);
displayMenu.add(errorItem);
displayMenu.add(warningItem);
displayMenu.add(infoItem);
displayMenu.add(noneItem);
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
代码示例来源:origin: magefree/mage
trayIcon.addActionListener(e -> {
stopBlink();
MageFrame frame = MageFrame.getInstance();
});
final SystemTray tray = SystemTray.getSystemTray();
final PopupMenu popup = new PopupMenu();
MenuItem imagesItem = new MenuItem("Download images");
MenuItem iconsItem = new MenuItem("Download icons");
MenuItem stopBlinkItem = new MenuItem("Stop blinking");
popup.add(imagesItem);
popup.add(iconsItem);
popup.add(stopBlinkItem);
popup.add(preferencesItem);
popup.addSeparator();
popup.add(aboutItem);
popup.addSeparator();
popup.add(exitItem);
tray.add(trayIcon);
} catch (AWTException e) {
log.error("TrayIcon could not be added: ", e);
代码示例来源:origin: stackoverflow.com
if (SystemTray.isSupported() == false) {
System.err.println("No system tray available");
return;
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);
item.addActionListener(menuActionListener);
popup.add(item);
ActionListener actionListener = new ActionListener() {
trayIcon.addActionListener(actionListener);
try {
tray.add(trayIcon);
代码示例来源:origin: net.imagej/ij
void addPopupItem(String s) {
MenuItem mi=new MenuItem(s);
mi.addActionListener(this);
pm.add(mi);
}
代码示例来源: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());
final PopupMenu popup = new PopupMenu();
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");
popup.add(aboutItem);
popup.addSeparator();
代码示例来源: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: chatty/chatty
public TrayIconManager(Image image) {
if (SystemTray.isSupported()) {
tray = SystemTray.getSystemTray();
popup = new PopupMenu();
MenuItem showItem = new MenuItem("Show");
showItem.setActionCommand("show");
popup.add(showItem);
MenuItem exitItem = new MenuItem("Exit");
exitItem.setActionCommand("exit");
popup.add(exitItem);
trayIcon = new TrayIcon(image, "Chatty");
trayIcon.setImageAutoSize(true);
trayIcon.setPopupMenu(popup);
} else {
tray = null;
trayIcon = null;
popup = null;
}
}
内容来源于网络,如有侵权,请联系作者删除!