List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:edu.clemson.cs.nestbed.client.gui.MessageMonitorFrame.java
private JMenu buildFileMenu() { JMenu menu = new JMenu("File"); JMenuItem close = new JMenuItem("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MessageMonitorFrame.this.setVisible(false); }//from w w w .j av a 2 s . c o m }); menu.add(close); return menu; }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_layer.java
private JMenuItem getAddOption() { JMenuItem addItem = new JMenuItem("Add " + networkElementType); addItem.addActionListener(new ActionListener() { @Override/*from w w w . j av a 2 s. c o m*/ public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); try { netPlan.addLayer("Layer " + netPlan.getNumberOfLayers(), null, null, null, null, null); final VisualizationState vs = callback.getVisualizationState(); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs .suggestCanvasUpdatedVisualizationLayerInfoForNewDesign( new HashSet<>(callback.getDesign().getNetworkLayers())); vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(), res.getSecond()); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LAYER)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ex.printStackTrace(); ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to add " + networkElementType); } } }); return addItem; }
From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java
private JMenu buildCategoryMenu() { JMenu categoryMenu = new JMenu("Categories"); categoryMenu.setMnemonic('t'); JMenuItem showItem = new JMenuItem("Show"); showItem.setMnemonic('s'); JMenuItem addCatButton = createAddCatMenuItem(); showItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getCategoriesNode()); }/*from w w w . j a va 2s . c om*/ }); categoryMenu.add(showItem); categoryMenu.addSeparator(); categoryMenu.add(addCatButton); return categoryMenu; }
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(); }/* w w w . j ava 2 s . com*/ }; 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:ScreenCapture.java
public ScreenCapture(String title) { super(title); setDefaultCloseOperation(EXIT_ON_CLOSE); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("File"); ActionListener al;// w w w.ja v a 2 s . c o m JMenuItem mi = new JMenuItem("Save"); al = new ActionListener() { public void actionPerformed(ActionEvent e) { save(); } }; mi.addActionListener(al); menu.add(mi); mb.add(menu); menu = new JMenu("Capture"); mi = new JMenuItem("Capture"); al = new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); BufferedImage biScreen = robot.createScreenCapture(rectScreenSize); setVisible(true); ia.setImage(biScreen); jsp.getHorizontalScrollBar().setValue(0); jsp.getVerticalScrollBar().setValue(0); } }; mi.addActionListener(al); menu.add(mi); mb.add(menu); mi = new JMenuItem("Crop"); al = new ActionListener() { public void actionPerformed(ActionEvent e) { if (ia.crop()) { jsp.getHorizontalScrollBar().setValue(0); jsp.getVerticalScrollBar().setValue(0); } } }; mi.addActionListener(al); menu.add(mi); mb.add(menu); setJMenuBar(mb); getContentPane().add(jsp = new JScrollPane(ia)); setVisible(true); }
From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java
private JMenuItem createAddCatMenuItem() { JMenuItem item = new JMenuItem("Add new"); item.setMnemonic('n'); item.setIcon(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADD)); item.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { addCategory();/*from www .j a v a2s . co m*/ } }); return item; }
From source file:TreeUtil.java
/** Creates the menus by using recursion */ public JMenuItem getMenus(DefaultMutableTreeNode node, JMenu parentMenu) { String name = node.getUserObject().toString(); int numChild = node.getChildCount(); if (numChild < 1) { JMenuItem tempMenu = new JMenuItem(name); tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name); tempMenu.addActionListener(this); return tempMenu; }/*from ww w .j av a 2 s. com*/ JMenu tempMenu = new JMenu(name); tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name); tempMenu.addActionListener(this); for (int i = 0; i < numChild; i++) { tempMenu.add(getMenus((DefaultMutableTreeNode) node.getChildAt(i), tempMenu)); } return tempMenu; }
From source file:gdt.jgui.base.JPropertyPanel.java
/** * Get context menu. //from www . j a v a 2 s .c om * @return context menu.. */ @Override public JMenu getContextMenu() { JMenu menu = new JMenu("Context"); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } else console.back(); } }); menu.add(doneItem); return menu; }
From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java
public void addJpgMenuItem(final Component parent, JPopupMenu popMenu) { JMenuItem mItem = new JMenuItem("Save as JPG..."); mItem.addActionListener(new ActionListener() { @Override//from w ww. j a v a2 s.c o m public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); FileFilter filter1 = new SimpleFilter("jpg", "JPG File (*.jpg)"); chooser.addChoosableFileFilter(filter1); int status = chooser.showSaveDialog(parent); if (status == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); try { String fileName = f.getAbsolutePath().toLowerCase(); if (!fileName.endsWith("jpg")) fileName += ".jpg"; saveAsJPEG(new File(fileName)); } catch (IOException ex) { JOptionPane.showMessageDialog(parent, "IOException: Could not save file", "IOException", JOptionPane.ERROR_MESSAGE); } } } }); popMenu.add(mItem); }
From source file:com.game.ui.views.MapEditor.java
public void generateGUI() throws IOException { setDefaultCloseOperation(DISPOSE_ON_CLOSE); // setResizable(false); JMenuBar menubar = new JMenuBar(); ImageIcon icon = null;//from w w w . j a v a 2s . c om try { icon = GameUtils.shrinkImage("save.png", 20, 20); } catch (IOException e) { System.out.println("Dialog : showDialogForMap(): Exception occured :" + e); e.printStackTrace(); } JMenu file = new JMenu("File"); JMenuItem save = new JMenuItem("Save", icon); save.setToolTipText("Save Map Information"); save.setActionCommand("Save Map"); save.addActionListener(this); file.add(save); menubar.add(file); setJMenuBar(menubar); JPanel topPanel = new JPanel(); topPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); topPanel.setLayout(new GridBagLayout()); JLabel headerLbl = new JLabel("Legend : "); headerLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); JLabel lbl1 = new JLabel(); lbl1.setPreferredSize(new Dimension(50, 20)); lbl1.setBackground(Configuration.pathColor); lbl1.setOpaque(true); JLabel lbl2 = new JLabel("- Represents the path."); JLabel lbl3 = new JLabel(); lbl3.setPreferredSize(new Dimension(50, 20)); lbl3.setBackground(Configuration.enemyColor); lbl3.setOpaque(true); JLabel lbl4 = new JLabel("- Represents the path with monsters"); JLabel lbl5 = new JLabel(); lbl5.setPreferredSize(new Dimension(50, 20)); lbl5.setBackground(Configuration.startPointColor); lbl5.setOpaque(true); JLabel lbl6 = new JLabel("- Represents the starting point in the path"); JLabel lbl7 = new JLabel(); lbl7.setBackground(Configuration.endPointColor); lbl7.setOpaque(true); lbl7.setPreferredSize(new Dimension(50, 20)); JLabel lbl8 = new JLabel("- Ending point in the path"); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.weightx = 1; c.weighty = 0; c.insets = new Insets(5, 5, 5, 5); c.gridwidth = 2; topPanel.add(headerLbl, c); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.ipadx = 5; c.ipady = 5; topPanel.add(lbl1, c); c.gridx = 1; c.anchor = GridBagConstraints.FIRST_LINE_START; topPanel.add(lbl2, c); c.gridx = 0; c.gridy = 2; topPanel.add(lbl3, c); c.gridx = 1; topPanel.add(lbl4, c); c.gridx = 0; c.gridy = 3; topPanel.add(lbl5, c); c.gridx = 1; topPanel.add(lbl6, c); c.gridx = 0; c.gridy = 4; topPanel.add(lbl7, c); c.gridx = 1; topPanel.add(lbl8, c); add(topPanel, BorderLayout.NORTH); bottomPanel = new JPanel(); add(bottomPanel, BorderLayout.CENTER); bottomPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); // bottomPanel.add(new JButton("kaushik")); pack(); setExtendedState(JFrame.MAXIMIZED_BOTH); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); setMaximizedBounds(env.getMaximumWindowBounds()); setVisible(true); callDialogForUsersInput(); }