List of usage examples for java.awt MenuItem MenuItem
public MenuItem(String label) throws HeadlessException
From source file:SysTray.java
public void installSystemTray() throws Exception { PopupMenu menu = new PopupMenu(); MenuItem exit = new MenuItem("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0);//www . ja va 2s . c o m } }); menu.add(exit); TrayIcon icon = new TrayIcon(getImage(), "Java application as a tray icon", menu); icon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Hi!"); } }); SystemTray.getSystemTray().add(icon); Thread.sleep(3000); icon.displayMessage("Attention", "Please click here", TrayIcon.MessageType.WARNING); }
From source file:PopupDemo.java
public PopupDemo() { MenuBar mb = new MenuBar(); setMenuBar(mb);//from w w w .j a v a2 s.c om Menu m = new Menu("file"); mb.add(m); MenuItem item = new MenuItem("file-1"); item.addActionListener(this); m.add(item); item = new MenuItem("file-2"); m.add(item); setSize(100, 100); setLayout(new BorderLayout()); Label l = new Label("label"); addPopup(l, "label"); add(l, "North"); Panel p = new Panel(); addPopup(p, "Panel"); add(p, "Center"); Button b = new Button("button"); addPopup(b, "button"); add(b, "South"); }
From source file:JDK6SplashTest.java
public JDK6SplashTest() { super("SplashScreen demo"); setSize(500, 300);/*from ww w .j a va 2 s .c o m*/ setLayout(new BorderLayout()); Menu m1 = new Menu("File"); MenuItem mi1 = new MenuItem("Exit"); m1.add(mi1); mi1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); MenuBar mb = new MenuBar(); setMenuBar(mb); mb.add(m1); final SplashScreen splash = SplashScreen.getSplashScreen(); if (splash == null) { System.out.println("SplashScreen.getSplashScreen() returned null"); return; } Graphics2D g = (Graphics2D) splash.createGraphics(); if (g == null) { System.out.println("g is null"); return; } for (int i = 0; i < 100; i++) { renderSplashFrame(g, i); splash.update(); try { Thread.sleep(200); } catch (InterruptedException e) { } } splash.close(); setVisible(true); toFront(); }
From source file:coolmapplugin.impl.CMCyCommunicationPlugin.java
private void initMenuItems() { CoolMapMaster.getCMainFrame().addMenuSeparator("Plugin"); MenuItem item = new MenuItem("Without aggregated values"); CoolMapMaster.getCMainFrame().addMenuItem("Plugin/Cytoscape/Map nodes/", item, false, false); item.addActionListener(new MapSelectedToCytoscape()); CoolMapMaster.getCMainFrame().addMenuSeparator("Plugin"); item = new MenuItem("Find Cytoscape selection in CoolMap"); CoolMapMaster.getCMainFrame().addMenuItem("Plugin/Cytoscape", item, false, false); item.addActionListener(new MapSelectedFromCytoscape()); CoolMapMaster.getCMainFrame().addMenuSeparator("Plugin"); item = new MenuItem("Mean"); CoolMapMaster.getCMainFrame().addMenuItem("Plugin/Cytoscape/Map nodes/With aggregated values", item, false, false);/* w w w. ja va2 s . com*/ item.addActionListener(new MapSelectedToCytoscapeWithAggregatedValue( MapSelectedToCytoscapeWithAggregatedValue.AggregationType.MEAN)); CoolMapMaster.getCMainFrame().addMenuSeparator("Plugin"); item = new MenuItem("Sum"); CoolMapMaster.getCMainFrame().addMenuItem("Plugin/Cytoscape/Map nodes/With aggregated values", item, false, false); item.addActionListener(new MapSelectedToCytoscapeWithAggregatedValue( MapSelectedToCytoscapeWithAggregatedValue.AggregationType.SUM)); CoolMapMaster.getCMainFrame().addMenuSeparator("Plugin"); item = new MenuItem("Max"); CoolMapMaster.getCMainFrame().addMenuItem("Plugin/Cytoscape/Map nodes/With aggregated values", item, false, false); item.addActionListener(new MapSelectedToCytoscapeWithAggregatedValue( MapSelectedToCytoscapeWithAggregatedValue.AggregationType.MAX)); CoolMapMaster.getCMainFrame().addMenuSeparator("Plugin"); item = new MenuItem("Min"); CoolMapMaster.getCMainFrame().addMenuItem("Plugin/Cytoscape/Map nodes/With aggregated values", item, false, false); item.addActionListener(new MapSelectedToCytoscapeWithAggregatedValue( MapSelectedToCytoscapeWithAggregatedValue.AggregationType.MIN)); CoolMapMaster.getCMainFrame().addMenuSeparator("Plugin"); item = new MenuItem("Median"); CoolMapMaster.getCMainFrame().addMenuItem("Plugin/Cytoscape/Map nodes/With aggregated values", item, false, false); item.addActionListener(new MapSelectedToCytoscapeWithAggregatedValue( MapSelectedToCytoscapeWithAggregatedValue.AggregationType.MEDIAN)); }
From source file:coolmap.module.impl.SideMapModule.java
public static void registerSideMapRow(final Class<RowMap> rowMap) { rowMaps.add(rowMap);//from w w w. ja va2 s . c o m //Also add to menu // System.err.println(rowMap); try { MenuItem item = new MenuItem( ((RowMap) rowMap.getConstructor(CoolMapObject.class).newInstance(new CoolMapObject())) .getName()); CoolMapMaster.getCMainFrame().addMenuItem("View/Canvas config/Row side/", item, false, false); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { CoolMapObject object = CoolMapMaster.getActiveCoolMapObject(); object.getCoolMapView() .addRowMap(rowMap.getConstructor(CoolMapObject.class).newInstance(object)); } catch (Exception ex) { // ex.printStackTrace(); //need an error logging system } } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:ListenerReuse.java
public ListenerReuse() { Button b = new Button("Save"); add(b);// w ww . j av a2s.c om MenuBar mb = new MenuBar(); setMenuBar(mb); Menu fm = new Menu("File"); mb.add(fm); MenuItem mi = new MenuItem("Save"); fm.add(mi); // Construct the ActionListener, and keep a reference to it. ActionListener saver = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Saving your file..."); // In real life we would call the doSave() method // in the main class, something like this: // mainProg.doSave(); } }; // Register the actionListener with the Button b.addActionListener(saver); // And now register the same actionListener with the MenuItem mi.addActionListener(saver); pack(); }
From source file:misc.TrayIconDemo.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;/* w w w. j av a 2s . co m*/ } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("images/bulb.gif", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components 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"); MenuItem exitItem = new MenuItem("Exit"); //Add components to popup menu 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); try { tray.add(trayIcon); } catch (AWTException e) { System.out.println("TrayIcon could not be added."); return; } trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray"); } }); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from the About menu item"); } }); cb1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb1Id = e.getStateChange(); if (cb1Id == ItemEvent.SELECTED) { trayIcon.setImageAutoSize(true); } else { trayIcon.setImageAutoSize(false); } } }); cb2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb2Id = e.getStateChange(); if (cb2Id == ItemEvent.SELECTED) { trayIcon.setToolTip("Sun TrayIcon"); } else { trayIcon.setToolTip(null); } } }); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuItem item = (MenuItem) e.getSource(); //TrayIcon.MessageType type = null; System.out.println(item.getLabel()); if ("Error".equals(item.getLabel())) { //type = TrayIcon.MessageType.ERROR; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR); } else if ("Warning".equals(item.getLabel())) { //type = TrayIcon.MessageType.WARNING; trayIcon.displayMessage("Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING); } else if ("Info".equals(item.getLabel())) { //type = TrayIcon.MessageType.INFO; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO); } else if ("None".equals(item.getLabel())) { //type = TrayIcon.MessageType.NONE; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE); } } }; errorItem.addActionListener(listener); warningItem.addActionListener(listener); infoItem.addActionListener(listener); noneItem.addActionListener(listener); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:SplashDemo.java
public SplashDemo() { super("SplashScreen demo"); setSize(300, 200);/* ww w . j a v a 2s . c om*/ setLayout(new BorderLayout()); Menu m1 = new Menu("File"); MenuItem mi1 = new MenuItem("Exit"); m1.add(mi1); mi1.addActionListener(this); this.addWindowListener(closeWindow); MenuBar mb = new MenuBar(); setMenuBar(mb); mb.add(m1); final SplashScreen splash = SplashScreen.getSplashScreen(); if (splash == null) { System.out.println("SplashScreen.getSplashScreen() returned null"); return; } Graphics2D g = splash.createGraphics(); if (g == null) { System.out.println("g is null"); return; } for (int i = 0; i < 100; i++) { renderSplashFrame(g, i); splash.update(); try { Thread.sleep(90); } catch (InterruptedException e) { } } splash.close(); setVisible(true); toFront(); }
From source file:org.kootox.episodesmanager.ui.systray.EpisodesTrayIcon.java
public void create() { //Check the SystemTray support if (!SystemTray.isSupported()) { if (log.isInfoEnabled()) { log.info("SystemTray is not supported"); }//from w w w. j a v a2 s . c o m return; } if (loaded) { return; } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("systray.png", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem display = new MenuItem("Display"); MenuItem exit = new MenuItem("Exit"); //Add components to popup menu popup.add(display); popup.addSeparator(); popup.add(exit); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { if (log.isDebugEnabled()) { log.debug("TrayIcon could not be added."); } return; } trayIcon.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent mouseEvent) { if (mouseEvent.getButton() == MouseEvent.BUTTON1) { showHide(); } } @Override public void mousePressed(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseReleased(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseEntered(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseExited(MouseEvent mouseEvent) { //Do nothing } }); display.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showHide(); } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EpisodesManagerMainUI mainUI = EpisodesManagerContext.MAIN_UI_ENTRY_DEF.getContextValue(context); mainUI.close(); } }); loaded = true; if (log.isDebugEnabled()) { log.debug("Systray loaded"); } }
From source file:org.keyboardplaying.messaging.ui.ApplicationManager.java
private PopupMenu makeMenu() { // Create a pop-up menu components MenuItem exitItem = new MenuItem("Exit"); exitItem.addActionListener(new ActionListener() { @Override//w w w.j a v a 2 s . co m public void actionPerformed(ActionEvent e) { context.close(); } }); // Add components to pop-up menu PopupMenu popup = new PopupMenu(); popup.add(exitItem); return popup; }