List of usage examples for java.awt CheckboxMenuItem CheckboxMenuItem
public CheckboxMenuItem(String label) throws HeadlessException
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;/*from ww w . j av a 2 s.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:AnotherMenuDemo.java
AnotherMenuDemo(String s) { super("MenuDemo: " + s); Container cp = this; cp.setLayout(new FlowLayout()); mb = new MenuBar(); setMenuBar(mb); // Frame implements MenuContainer MenuItem mi;//from ww w. ja v a 2 s. c o m // The File Menu... fm = new Menu("File"); fm.add(mi = new MenuItem("Open", new MenuShortcut('O'))); mi.addActionListener(this); fm.add(mi = new MenuItem("Close", new MenuShortcut('W'))); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new MenuItem("Print", new MenuShortcut('P'))); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new MenuItem("Exit", new MenuShortcut('Q'))); exitItem = mi; // save for action handler mi.addActionListener(this); mb.add(fm); // The Options Menu... om = new Menu("Options"); cb = new CheckboxMenuItem("AutoSave"); cb.setState(true); cb.addItemListener(this); om.add(cb); opSubm = new Menu("SubOptions"); opSubm.add(new MenuItem("Alpha")); opSubm.add(new MenuItem("Gamma")); opSubm.add(new MenuItem("Delta")); om.add(opSubm); mb.add(om); // The Help Menu... hm = new Menu("Help"); hm.add(mi = new MenuItem("About")); mi.addActionListener(this); hm.add(mi = new MenuItem("Topics")); mi.addActionListener(this); mb.add(hm); mb.setHelpMenu(hm); // needed for portability (Motif, etc.). // the main window cp.add(new Label("Menu Demo Window", 200, 150)); pack(); }
From source file:de.jakop.ngcalsync.application.TrayStarter.java
private void moveToTray(final Settings settings, final Application application) { final PopupMenu popup = new PopupMenu(); // Create a pop-up menu components final MenuItem syncItem = new MenuItem(UserMessage.get().MENU_ITEM_SYNCHRONIZE()); final CheckboxMenuItem schedulerItem = new CheckboxMenuItem(UserMessage.get().MENU_ITEM_SCHEDULER_ACTIVE()); final MenuItem logItem = new MenuItem(UserMessage.get().MENU_ITEM_SHOW_LOG()); final MenuItem aboutItem = new MenuItem(UserMessage.get().MENU_ITEM_ABOUT()); final MenuItem exitItem = new MenuItem(UserMessage.get().MENU_ITEM_EXIT()); // let the tray icon listen to sync events for state change application.addObserver(getTrayIcon()); //Add components to pop-up menu popup.add(syncItem);//from ww w. j a v a 2 s . com popup.add(schedulerItem); popup.add(logItem); popup.add(aboutItem); popup.addSeparator(); popup.add(exitItem); getTrayIcon().setPopupMenu(popup); application.reloadSettings(); final JFrame logWindow = createLogWindow(Level.toLevel(settings.getPopupThresholdLevel(), Level.INFO)); final JFrame aboutWindow = createAboutWindow(); final ActionListener syncActionListener = createSyncActionListener(application.getScheduler()); syncItem.addActionListener(syncActionListener); // sync also on double click getTrayIcon().addActionListener(syncActionListener); getTrayIcon().addMouseListener(createLogMouseListener(logWindow)); schedulerItem.addItemListener(createSchedulerItemListener(settings, application)); logItem.addActionListener(createLogActionListener(logWindow)); aboutItem.addActionListener(createAboutActionListener(aboutWindow)); exitItem.addActionListener(createExitActionListener(logWindow, aboutWindow)); schedulerItem.setState(settings.isSchedulerStarted()); toggleScheduler(settings.isSchedulerStarted(), settings, application); }
From source file:MDIApp.java
private MenuBar createMenuBar() { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { String command = ae.getActionCommand(); if (command.equals("Open")) { if (fd == null) { fd = new FileDialog(MDIApp.this, "Open File", FileDialog.LOAD); fd.setDirectory("/movies"); }//from w w w . j a va 2 s .c o m fd.show(); if (fd.getFile() != null) { String filename = fd.getDirectory() + fd.getFile(); openFile("file:" + filename); } } else if (command.equals("Exit")) { dispose(); System.exit(0); } } }; MenuItem item; MenuBar mb = new MenuBar(); // File Menu Menu mnFile = new Menu("File"); mnFile.add(item = new MenuItem("Open")); item.addActionListener(al); mnFile.add(item = new MenuItem("Exit")); item.addActionListener(al); // Options Menu Menu mnOptions = new Menu("Options"); cbAutoLoop = new CheckboxMenuItem("Auto replay"); cbAutoLoop.setState(true); mnOptions.add(cbAutoLoop); mb.add(mnFile); mb.add(mnOptions); return mb; }
From source file:ExTransform.java
public void initialize(String[] args) { // Initialize the window, menubar, etc. super.initialize(args); exampleFrame.setTitle("Java 3D Transform Example"); // Add a menu to select among transform options Menu mt = new Menu("Transform"); switchMenu = new CheckboxMenuItem[options.length]; for (int i = 0; i < options.length; i++) { switchMenu[i] = new CheckboxMenuItem(options[i].name); switchMenu[i].addItemListener(this); switchMenu[i].setState(false);/*ww w .ja va2 s.c o m*/ mt.add(switchMenu[i]); } exampleMenuBar.add(mt); currentSwitch = 0; switchMenu[currentSwitch].setState(true); }
From source file:com.piusvelte.taplock.server.TapLockServer.java
private static void initialize() { (new File(APP_PATH)).mkdir(); if (OS == OS_WIN) Security.addProvider(new BouncyCastleProvider()); System.out.println("APP_PATH: " + APP_PATH); try {// w ww. j a v a 2 s .c o m sLogFileHandler = new FileHandler(sLog); } catch (SecurityException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } catch (IOException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } File propertiesFile = new File(sProperties); if (!propertiesFile.exists()) { try { propertiesFile.createNewFile(); } catch (IOException e) { writeLog("propertiesFile.createNewFile: " + e.getMessage()); } } Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); if (prop.isEmpty()) { prop.setProperty(sPassphraseKey, sPassphrase); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } else { if (prop.containsKey(sPassphraseKey)) sPassphrase = prop.getProperty(sPassphraseKey); else prop.setProperty(sPassphraseKey, sPassphrase); if (prop.containsKey(sDisplaySystemTrayKey)) sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey)); else prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); if (prop.containsKey(sDebuggingKey)) sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey)); else prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); } } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (sLogFileHandler != null) { sLogger = Logger.getLogger("TapLock"); sLogger.setUseParentHandlers(false); sLogger.addHandler(sLogFileHandler); SimpleFormatter sf = new SimpleFormatter(); sLogFileHandler.setFormatter(sf); writeLog("service starting"); } if (sDisplaySystemTray && SystemTray.isSupported()) { final SystemTray systemTray = SystemTray.getSystemTray(); Image trayIconImg = Toolkit.getDefaultToolkit() .getImage(TapLockServer.class.getResource("/systemtrayicon.png")); final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock"); trayIcon.setImageAutoSize(true); PopupMenu popupMenu = new PopupMenu(); MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray"); toggleSystemTrayIcon.setState(sDisplaySystemTray); CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging"); toggleDebugging.setState(sDebugging); MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server"); popupMenu.add(aboutItem); popupMenu.add(toggleSystemTrayIcon); if (OS == OS_WIN) { MenuItem setPasswordItem = new MenuItem("Set password"); popupMenu.add(setPasswordItem); setPasswordItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel panel = new JPanel(); JLabel label = new JLabel("Enter your Windows account password:"); JPasswordField passField = new JPasswordField(32); panel.add(label); panel.add(passField); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (option == 0) { String password = encryptString(new String(passField.getPassword())); if (password != null) { Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sPasswordKey, password); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e1) { writeLog("prop load: " + e1.getMessage()); } catch (IOException e1) { writeLog("prop load: " + e1.getMessage()); } } } } }); } popupMenu.add(toggleDebugging); popupMenu.add(shutdownItem); trayIcon.setPopupMenu(popupMenu); try { systemTray.add(trayIcon); } catch (AWTException e) { writeLog("systemTray.add: " + e.getMessage()); } aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String newline = System.getProperty("line.separator"); newline += newline; JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel" + newline + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version." + newline + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details." + newline + "You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." + newline + "Bryan Emmanuel piusvelte@gmail.com"); } }); toggleSystemTrayIcon.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED); if (!sDisplaySystemTray) systemTray.remove(trayIcon); } }); toggleDebugging.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setDebugging(e.getStateChange() == ItemEvent.SELECTED); } }); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { shutdown(); } }); } synchronized (sConnectionThreadLock) { (sConnectionThread = new ConnectionThread()).start(); } }
From source file:MonitorSaurausRex.MainMenu.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;//from ww w .j a v a 2 s . c om } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("Logo.png", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); trayIcon.setImageAutoSize(true); // Create a popup menu components MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem cb1 = new CheckboxMenuItem("Menu"); CheckboxMenuItem cb2 = new CheckboxMenuItem("Quarantine!"); Menu displayMenu = new Menu("Actions"); MenuItem errorItem = new MenuItem("Cut Connections"); MenuItem warningItem = new MenuItem("Send Reports"); MenuItem infoItem = new MenuItem("Kill Processes"); 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); 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, "MonitorSaurausRex, Designed for sec203 group project. The program was designed to be piece of software to combat Ransomware" + " in a corparate enviroment. The Project was created by Luke Barlow, Dayan Patel, Rob Shire and Sian Skiggs."); } }); cb1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb1Id = e.getStateChange(); trayIcon.setImageAutoSize(true); if (cb1Id == ItemEvent.SELECTED) { trayIcon.setImageAutoSize(true); } else { trayIcon.setImageAutoSize(true); } } }); 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); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:ExSwitch.java
public void initialize(String[] args) { // Initialize the window, menubar, etc. super.initialize(args); exampleFrame.setTitle("Java 3D Switch Example"); // Add a menu to select among switch options Menu mt = new Menu("Switch"); switchMenu = new CheckboxMenuItem[options.length]; for (int i = 0; i < options.length; i++) { switchMenu[i] = new CheckboxMenuItem(options[i].name); switchMenu[i].addItemListener(this); switchMenu[i].setState(false);/*w ww .j a va2 s . c o m*/ mt.add(switchMenu[i]); } exampleMenuBar.add(mt); currentSwitch = 0; switchMenu[currentSwitch].setState(true); }
From source file:ExBluePrint.java
public void initialize(String[] args) { // Initialize the window, menubar, etc. super.initialize(args); exampleFrame.setTitle("Java 3D Blueprint Example"); //// w w w .j av a 2s . c o m // Add a menubar menu to change parameters // (images) // -------- // Wireframe // Shaded // // Add a menu to select among background and shading options Menu m = new Menu("Options"); imageMenu = new CheckboxMenuItem[images.length]; for (int i = 0; i < images.length; i++) { imageMenu[i] = new CheckboxMenuItem(images[i].name); imageMenu[i].addItemListener(this); imageMenu[i].setState(false); m.add(imageMenu[i]); } imageMenu[currentImage].setState(true); m.addSeparator(); appearanceMenu = new CheckboxMenuItem[2]; appearanceMenu[0] = new CheckboxMenuItem("Wireframe"); appearanceMenu[0].addItemListener(this); appearanceMenu[0].setState(false); m.add(appearanceMenu[0]); appearanceMenu[1] = new CheckboxMenuItem("Shaded"); appearanceMenu[1].addItemListener(this); appearanceMenu[1].setState(true); m.add(appearanceMenu[1]); exampleMenuBar.add(m); // Preload background images TextureLoader texLoader = null; imageComponents = new ImageComponent2D[images.length]; String value = null; for (int i = 0; i < images.length; i++) { value = (String) images[i].value; if (value == null) { imageComponents[i] = null; continue; } texLoader = new TextureLoader(value, this); imageComponents[i] = texLoader.getImage(); } }
From source file:ExSpotLight.java
public void initialize(String[] args) { // Initialize the window, menubar, etc. super.initialize(args); exampleFrame.setTitle("Java 3D Spot Light Example"); ///*from www . j a va 2s .c o m*/ // Add a menubar menu to change node parameters // Light on/off // Color --> // Position --> // Direction --> // Attenuation --> // Spread Angle --> // Concentration --> // Menu m = new Menu("SpotLight"); lightOnOffMenu = new CheckboxMenuItem("Light on/off"); lightOnOffMenu.addItemListener(this); lightOnOffMenu.setState(lightOnOff); m.add(lightOnOffMenu); colorMenu = new CheckboxMenu("Color", colors, currentColor, this); m.add(colorMenu); positionMenu = new CheckboxMenu("Position", positions, currentPosition, this); m.add(positionMenu); directionMenu = new CheckboxMenu("Direction", directions, currentDirection, this); m.add(directionMenu); attenuationMenu = new CheckboxMenu("Attenuation", attenuations, currentAttenuation, this); m.add(attenuationMenu); spreadMenu = new CheckboxMenu("Spread Angle", spreads, currentSpread, this); m.add(spreadMenu); concentrationMenu = new CheckboxMenu("Concentration", concentrations, currentConcentration, this); m.add(concentrationMenu); exampleMenuBar.add(m); }