List of usage examples for javax.swing JCheckBoxMenuItem JCheckBoxMenuItem
public JCheckBoxMenuItem(Action a)
From source file:Main.java
/** * Creates a {@link JCheckBoxMenuItem} for a menu or {@link JToggleButton} * for a tool bar// ww w . j ava 2 s .co m * * @param menuOrToolBar * @param action * @throws NoSuchMethodException * @throws IllegalAccessException * @throws InvocationTargetException */ public static void addBooleanActionTo(Container menuOrToolBar, Action action) { Method addButton; try { addButton = Container.class.getMethod("add", Component.class); if (menuOrToolBar instanceof JMenu) { addButton.invoke(menuOrToolBar, new JCheckBoxMenuItem(action)); } else { final JToggleButton jToggleButton = new JToggleButton(action); jToggleButton.setText(null); addButton.invoke(menuOrToolBar, jToggleButton); } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); } }
From source file:org.esa.beam.visat.toolviews.stat.MaskSelectionToolSupport.java
public JCheckBoxMenuItem createMaskSelectionModeMenuItem() { final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(String.format("Select Mask '%s'", maskName)); menuItem.setName("maskSelectionMode"); menuItem.addActionListener(new ActionListener() { @Override// w ww .j av a 2s. co m public void actionPerformed(ActionEvent e) { if (menuItem.isSelected()) { if (plotAreaSelectionTool == null) { plotAreaSelectionTool = new PlotAreaSelectionTool(chartPanel, MaskSelectionToolSupport.this); plotAreaSelectionTool.setAreaType(areaType); plotAreaSelectionTool.setFillPaint(createAlphaColor(maskColor, 50)); } plotAreaSelectionTool.install(); } else { if (plotAreaSelectionTool != null) { plotAreaSelectionTool.uninstall(); } } } }); return menuItem; }
From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java
public HistoChartPanel(final JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips, final ModelMaker modelMaker) { super(chart, properties, save, print, zoom, tooltips); this.modelMaker = modelMaker; // horizontal zoom doesn't work, by setting false we don't get bogus menu item // setHorizontalZoom(false); // setVerticalZoom(true); final JCheckBoxMenuItem logYScale = new JCheckBoxMenuItem( ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.test.logscale.y")); logYScale.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { CategoryPlot p = (CategoryPlot) chart.getPlot(); Axis oldAxis = p.getRangeAxis(); if (logYScale.isSelected()) { LogarithmicAxis yAxis = new LogarithmicAxis(ChoiceMakerCoreMessages.m .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs")); yAxis.setStrictValuesFlag(false); p.setRangeAxis(yAxis);//from w w w. j a v a 2 s.com } else { p.setRangeAxis(new NumberAxis(ChoiceMakerCoreMessages.m .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"))); } oldAxis.setPlot(null); chartChanged(new ChartChangeEvent(this)); } }); JPopupMenu popup = getPopupMenu(); popup.addSeparator(); popup.add(logYScale); popup.addSeparator(); select = new JMenu("Select"); final JMenuItem all = new JMenuItem("All"); select.add(all); final JMenuItem cmDiffer = new JMenuItem("Human marked differ"); select.add(cmDiffer); final JMenuItem cmHold = new JMenuItem("Human marked hold"); select.add(cmHold); final JMenuItem cmMatch = new JMenuItem("Human marked match"); select.add(cmMatch); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ev) { ListeningMarkedRecordPairFilter filter = modelMaker.getFilter(); filter.reset(); filter.setFromPercentage(rangeFrom); filter.setToPercentage(rangeTo); Object src = ev.getSource(); if (src != all) { boolean[] b = new boolean[Decision.NUM_DECISIONS]; if (src == cmDiffer) { b[Decision.DIFFER.toInt()] = true; } else if (src == cmHold) { b[Decision.HOLD.toInt()] = true; } else if (src == cmMatch) { b[Decision.MATCH.toInt()] = true; } filter.setHumanDecision(b); } modelMaker.filterMarkedRecordPairList(); } }; all.addActionListener(l); cmDiffer.addActionListener(l); cmHold.addActionListener(l); cmMatch.addActionListener(l); popup.add(select); addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent evt) { ChartEntity e = evt.getEntity(); if (e instanceof CategoryItemEntity) { CategoryItemEntity c = (CategoryItemEntity) e; int cat = c.getCategoryIndex(); HistoCategoryDataset data = (HistoCategoryDataset) ((CategoryPlot) getChart().getPlot()) .getDataset(); int len = data.getColumnCount(); float step = 1f / len; rangeFrom = cat * step; rangeTo = rangeFrom + step; ListeningMarkedRecordPairFilter filter = modelMaker.getFilter(); filter.reset(); filter.setFromPercentage(rangeFrom); filter.setToPercentage(rangeTo); boolean[] b = new boolean[Decision.NUM_DECISIONS]; int series = c.getSeries(); if (data.isIncludeHolds() && series != 0) { if (series == 1) { series = 2; } else { series = 1; } } b[series] = true; filter.setHumanDecision(b); modelMaker.filterMarkedRecordPairList(); } } public void chartMouseMoved(ChartMouseEvent arg0) { } }); }
From source file:IntroExample.java
public IntroExample() { JMenu fileMenu = new JMenu("File"); JMenu editMenu = new JMenu("Edit"); JMenu otherMenu = new JMenu("Other"); JMenu subMenu = new JMenu("SubMenu"); JMenu subMenu2 = new JMenu("SubMenu2"); // Assemble the File menus with mnemonics ActionListener printListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Menu item [" + event.getActionCommand() + "] was pressed."); }/*w ww . j a va 2 s . co m*/ }; for (int i = 0; i < fileItems.length; i++) { JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i]); item.addActionListener(printListener); fileMenu.add(item); } // Assemble the File menus with keyboard accelerators for (int i = 0; i < editItems.length; i++) { JMenuItem item = new JMenuItem(editItems[i]); item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i], Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); item.addActionListener(printListener); editMenu.add(item); } // Insert a separator in the Edit Menu in Position 1 after "Undo" editMenu.insertSeparator(1); // Assemble the submenus of the Other Menu JMenuItem item; subMenu2.add(item = new JMenuItem("Extra 2")); item.addActionListener(printListener); subMenu.add(item = new JMenuItem("Extra 1")); item.addActionListener(printListener); subMenu.add(subMenu2); // Assemble the Other Menu itself otherMenu.add(subMenu); otherMenu.add(item = new JCheckBoxMenuItem("Check Me")); item.addActionListener(printListener); otherMenu.addSeparator(); ButtonGroup buttonGroup = new ButtonGroup(); otherMenu.add(item = new JRadioButtonMenuItem("Radio 1")); item.addActionListener(printListener); buttonGroup.add(item); otherMenu.add(item = new JRadioButtonMenuItem("Radio 2")); item.addActionListener(printListener); buttonGroup.add(item); otherMenu.addSeparator(); otherMenu.add(item = new JMenuItem("Potted Plant", new ImageIcon("image.gif"))); item.addActionListener(printListener); // Finally, add all the menus to the menu bar add(fileMenu); add(editMenu); add(otherMenu); }
From source file:MenuTest.java
public MenuFrame() { setTitle("MenuTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); fileMenu.add(new TestAction("New")); // demonstrate accelerators JMenuItem openItem = fileMenu.add(new TestAction("Open")); openItem.setAccelerator(KeyStroke.getKeyStroke("ctrl O")); fileMenu.addSeparator();/* www . j a v a 2 s.c o m*/ saveAction = new TestAction("Save"); JMenuItem saveItem = fileMenu.add(saveAction); saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S")); saveAsAction = new TestAction("Save As"); fileMenu.add(saveAsAction); fileMenu.addSeparator(); fileMenu.add(new AbstractAction("Exit") { public void actionPerformed(ActionEvent event) { System.exit(0); } }); // demonstrate check box and radio button menus readonlyItem = new JCheckBoxMenuItem("Read-only"); readonlyItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { boolean saveOk = !readonlyItem.isSelected(); saveAction.setEnabled(saveOk); saveAsAction.setEnabled(saveOk); } }); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert"); insertItem.setSelected(true); JRadioButtonMenuItem overtypeItem = new JRadioButtonMenuItem("Overtype"); group.add(insertItem); group.add(overtypeItem); // demonstrate icons Action cutAction = new TestAction("Cut"); cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif")); Action copyAction = new TestAction("Copy"); copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif")); Action pasteAction = new TestAction("Paste"); pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif")); JMenu editMenu = new JMenu("Edit"); editMenu.add(cutAction); editMenu.add(copyAction); editMenu.add(pasteAction); // demonstrate nested menus JMenu optionMenu = new JMenu("Options"); optionMenu.add(readonlyItem); optionMenu.addSeparator(); optionMenu.add(insertItem); optionMenu.add(overtypeItem); editMenu.addSeparator(); editMenu.add(optionMenu); // demonstrate mnemonics JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('H'); JMenuItem indexItem = new JMenuItem("Index"); indexItem.setMnemonic('I'); helpMenu.add(indexItem); // you can also add the mnemonic key to an action Action aboutAction = new TestAction("About"); aboutAction.putValue(Action.MNEMONIC_KEY, new Integer('A')); helpMenu.add(aboutAction); // add all top-level menus to menu bar JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); // demonstrate pop-ups popup = new JPopupMenu(); popup.add(cutAction); popup.add(copyAction); popup.add(pasteAction); JPanel panel = new JPanel(); panel.setComponentPopupMenu(popup); add(panel); // the following line is a workaround for bug 4966109 panel.addMouseListener(new MouseAdapter() { }); }
From source file:com.eviware.soapui.support.log.JLogList.java
public JLogList(String title) { super(new BorderLayout()); this.title = title; model = new LogListModel(); logList = new JList(model); logList.setToolTipText(title);/*w w w. j a va 2 s .com*/ logList.setCellRenderer(new LogAreaCellRenderer()); logList.setPrototypeCellValue("Testing 123"); logList.setFixedCellWidth(-1); JPopupMenu listPopup = new JPopupMenu(); listPopup.add(new ClearAction()); enableAction = new EnableAction(); enableMenuItem = new JCheckBoxMenuItem(enableAction); enableMenuItem.setSelected(true); listPopup.add(enableMenuItem); listPopup.addSeparator(); listPopup.add(new CopyAction()); listPopup.add(new SetMaxRowsAction()); listPopup.addSeparator(); listPopup.add(new ExportToFileAction()); logList.setComponentPopupMenu(listPopup); setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); JScrollPane scrollPane = new JScrollPane(logList); UISupport.addPreviewCorner(scrollPane, true); add(scrollPane, BorderLayout.CENTER); requestAttributes = new SimpleAttributeSet(); StyleConstants.setForeground(requestAttributes, Color.BLUE); responseAttributes = new SimpleAttributeSet(); StyleConstants.setForeground(responseAttributes, Color.GREEN); try { maxRows = Long.parseLong(SoapUI.getSettings().getString("JLogList#" + title, "1000")); } catch (NumberFormatException e) { } }
From source file:net.chaosserver.timelord.swingui.CommonTaskPopupMenu.java
/** * Constructs the default popup by putting all menu items into their default * state.//from w ww . j a v a 2 s.co m */ public CommonTaskPopupMenu() { if (log.isTraceEnabled()) { log.trace("Building the CommonTaskPopupMenu"); } addTaskItem = new JMenuItem("Add Task"); addTaskItem.setActionCommand(ACTION_ADDTASK); add(addTaskItem); addTimeItem = new JMenuItem("Add Time"); addTimeItem.setActionCommand(ACTION_ADDTIME); add(addTimeItem); addSeparator(); deleteTaskItem = new JMenuItem("Delete Task"); deleteTaskItem.setActionCommand(ACTION_DELTASK); deleteTaskItem.setEnabled(false); add(deleteTaskItem); renameMenuItem = new JMenuItem("Rename Task"); renameMenuItem.setActionCommand(ACTION_RENTASK); renameMenuItem.setEnabled(false); add(renameMenuItem); exportTaskItem = new JCheckBoxMenuItem("Export Task"); exportTaskItem.setActionCommand(ACTION_EXPORT); exportTaskItem.setSelected(false); exportTaskItem.setEnabled(false); add(exportTaskItem); hideTaskItem = new JMenuItem("Hide Task"); hideTaskItem.setActionCommand(ACTION_HIDETASK); hideTaskItem.setEnabled(false); add(hideTaskItem); editNoteItem = new JMenuItem("Edit Task Note"); editNoteItem.setActionCommand(ACTION_EDITNOTE); add(editNoteItem); }
From source file:InternalFrameTest.java
public DesktopFrame() { setTitle("InternalFrameTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); desktop = new JDesktopPane(); add(desktop, BorderLayout.CENTER); // set up menus JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w ww. jav a2 s . c o m*/ JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem openItem = new JMenuItem("New"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { createInternalFrame(new JLabel(new ImageIcon(planets[counter] + ".gif")), planets[counter]); counter = (counter + 1) % planets.length; } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenu windowMenu = new JMenu("Window"); menuBar.add(windowMenu); JMenuItem nextItem = new JMenuItem("Next"); nextItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { selectNextWindow(); } }); windowMenu.add(nextItem); JMenuItem cascadeItem = new JMenuItem("Cascade"); cascadeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { cascadeWindows(); } }); windowMenu.add(cascadeItem); JMenuItem tileItem = new JMenuItem("Tile"); tileItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tileWindows(); } }); windowMenu.add(tileItem); final JCheckBoxMenuItem dragOutlineItem = new JCheckBoxMenuItem("Drag Outline"); dragOutlineItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { desktop.setDragMode(dragOutlineItem.isSelected() ? JDesktopPane.OUTLINE_DRAG_MODE : JDesktopPane.LIVE_DRAG_MODE); } }); windowMenu.add(dragOutlineItem); }
From source file:TableRowColumnTest.java
public PlanetTableFrame() { setTitle("TableRowColumnTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); TableModel model = new DefaultTableModel(cells, columnNames) { public Class<?> getColumnClass(int c) { return cells[0][c].getClass(); }/*from w w w. jav a 2s .c o m*/ }; table = new JTable(model); table.setRowHeight(100); table.getColumnModel().getColumn(COLOR_COLUMN).setMinWidth(250); table.getColumnModel().getColumn(IMAGE_COLUMN).setMinWidth(100); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); sorter.setComparator(COLOR_COLUMN, new Comparator<Color>() { public int compare(Color c1, Color c2) { int d = c1.getBlue() - c2.getBlue(); if (d != 0) return d; d = c1.getGreen() - c2.getGreen(); if (d != 0) return d; return c1.getRed() - c2.getRed(); } }); sorter.setSortable(IMAGE_COLUMN, false); add(new JScrollPane(table), BorderLayout.CENTER); removedRowIndices = new HashSet<Integer>(); removedColumns = new ArrayList<TableColumn>(); final RowFilter<TableModel, Integer> filter = new RowFilter<TableModel, Integer>() { public boolean include(Entry<? extends TableModel, ? extends Integer> entry) { return !removedRowIndices.contains(entry.getIdentifier()); } }; // create menu JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu selectionMenu = new JMenu("Selection"); menuBar.add(selectionMenu); rowsItem = new JCheckBoxMenuItem("Rows"); columnsItem = new JCheckBoxMenuItem("Columns"); cellsItem = new JCheckBoxMenuItem("Cells"); rowsItem.setSelected(table.getRowSelectionAllowed()); columnsItem.setSelected(table.getColumnSelectionAllowed()); cellsItem.setSelected(table.getCellSelectionEnabled()); rowsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { table.clearSelection(); table.setRowSelectionAllowed(rowsItem.isSelected()); updateCheckboxMenuItems(); } }); selectionMenu.add(rowsItem); columnsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { table.clearSelection(); table.setColumnSelectionAllowed(columnsItem.isSelected()); updateCheckboxMenuItems(); } }); selectionMenu.add(columnsItem); cellsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { table.clearSelection(); table.setCellSelectionEnabled(cellsItem.isSelected()); updateCheckboxMenuItems(); } }); selectionMenu.add(cellsItem); JMenu tableMenu = new JMenu("Edit"); menuBar.add(tableMenu); JMenuItem hideColumnsItem = new JMenuItem("Hide Columns"); hideColumnsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int[] selected = table.getSelectedColumns(); TableColumnModel columnModel = table.getColumnModel(); // remove columns from view, starting at the last // index so that column numbers aren't affected for (int i = selected.length - 1; i >= 0; i--) { TableColumn column = columnModel.getColumn(selected[i]); table.removeColumn(column); // store removed columns for "show columns" command removedColumns.add(column); } } }); tableMenu.add(hideColumnsItem); JMenuItem showColumnsItem = new JMenuItem("Show Columns"); showColumnsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // restore all removed columns for (TableColumn tc : removedColumns) table.addColumn(tc); removedColumns.clear(); } }); tableMenu.add(showColumnsItem); JMenuItem hideRowsItem = new JMenuItem("Hide Rows"); hideRowsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int[] selected = table.getSelectedRows(); for (int i : selected) removedRowIndices.add(table.convertRowIndexToModel(i)); sorter.setRowFilter(filter); } }); tableMenu.add(hideRowsItem); JMenuItem showRowsItem = new JMenuItem("Show Rows"); showRowsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { removedRowIndices.clear(); sorter.setRowFilter(filter); } }); tableMenu.add(showRowsItem); JMenuItem printSelectionItem = new JMenuItem("Print Selection"); printSelectionItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int[] selected = table.getSelectedRows(); System.out.println("Selected rows: " + Arrays.toString(selected)); selected = table.getSelectedColumns(); System.out.println("Selected columns: " + Arrays.toString(selected)); } }); tableMenu.add(printSelectionItem); }
From source file:components.MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from w ww . j a v a2s .c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }