List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:ListCutPaste.java
/** * Create an Edit menu to support cut/copy/paste. *///w w w . ja v a 2 s . c o m public JMenuBar createMenuBar() { JMenuItem menuItem = null; JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); TransferActionListener actionListener = new TransferActionListener(); menuItem = new JMenuItem("Cut"); menuItem.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem("Copy"); menuItem.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem("Paste"); menuItem.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:ca.uviccscu.lp.server.main.MainFrame.java
@Deprecated public static void setupTablePopupOld() { JMenuItem menuItem = new JMenuItem("Start"); menuItem.addActionListener(new ActionListener() { @Override//from w w w . j a v a2 s . c o m public void actionPerformed(final ActionEvent e) { /* lockInterface(); l.trace(e.paramString()); int row = jTable1.rowAtPoint(new Point(Shared.guiLastTablePopupX, Shared.guiLastTablePopupY)); String game = (String) jTable1.getModel().getValueAt(row, 0); l.trace("Popup action! row: " + row + " and name " + game); int status = GamelistStorage.getGame(game).gameStatus; if (status == 0) { File g = new File(GamelistStorage.getGame(game).gameAbsoluteFolderPath); File tp = new File(Utils.concatenatePaths(new String[]{Shared.workingDirectory, Shared.torrentStoreSubDirectory})); try { TOTorrent t = TrackerManager.createNewTorrent(g, tp, new ProgressListener(game)); TrackerManager.getCore().addTorrentToTracker(t, tp.getAbsolutePath(), g.getAbsolutePath()); } catch (Exception ex) { l.error("Torrent create failed: " + game, ex); } } else if (status == 1||status == 2) { l.error("Game torrent already created"); } else { l.error("Game has been run already"); } unlockInterface(); * */ SwingWorker worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() { MainFrame.lockInterface(); l.trace(e.paramString()); int row = jTable1 .rowAtPoint(new Point(Shared.guiLastTablePopupX, Shared.guiLastTablePopupY)); String game = (String) jTable1.getModel().getValueAt(row, 0); l.trace("Popup start action! row: " + row + " and name " + game); int status = GamelistStorage.getGame(game).gameStatus; if (status == 0) { File g = new File(GamelistStorage.getGame(game).gameAbsoluteFolderPath); File tp = new File(Shared.workingDirectory + Shared.torrentStoreSubDirectory + "\\" + GamelistStorage.getGame(game).gameName + ".torrent"); try { MainFrame.setReportingActive(); TOTorrent t = TrackerManager.createNewTorrent(g, tp, new HashingProgressListener(game)); TrackerManager.getCore().addTorrentToTracker(t, tp.getAbsolutePath(), g.getAbsolutePath()); GamelistStorage.getGame(game).gameStatus = 1; MainFrame.setReportingIdle(); } catch (Exception ex) { l.error("Torrent create failed: " + game, ex); } } else if (status == 1 || status == 2) { l.error("Game torrent already created"); } else if (status == 4) { TrackerManager.getCore() .resumeTorrentSeeding(GamelistStorage.getGame(game).gameTorrent); TrackerManager.getCore() .resumeTorrentTracking(GamelistStorage.getGame(game).gameTorrent); } else { l.error("Game has been started already"); } return null; } @Override public void done() { MainFrame.updateProgressBar(-1, 0, 100000, "Idle", true, true); MainFrame.updateProgressBar(-1, 0, 100000, "Idle", false, true); MainFrame.updateTask("Idle...", true); MainFrame.unlockInterface(); } }; worker.execute(); } }); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem("Stop"); menuItem2.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { SwingWorker worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() { MainFrame.lockInterface(); l.trace(e.paramString()); int row = jTable1 .rowAtPoint(new Point(Shared.guiLastTablePopupX, Shared.guiLastTablePopupY)); String game = (String) jTable1.getModel().getValueAt(row, 0); l.trace("Popup stop action! row: " + row + " and name " + game); Game g = GamelistStorage.getGame(game); int status = g.gameStatus; if (status == 3) { try { TrackerManager.getCore() .pauseTorrentSeeding(GamelistStorage.getGame(game).gameTorrent); TrackerManager.getCore() .pauseTorrentTracking(GamelistStorage.getGame(game).gameTorrent); g.gameStatus = 4; } catch (Exception ex) { l.error("Torrent create failed: " + game, ex); } } else if (status == 1 || status == 2) { l.error("Game torrent already created"); } else { l.error("Game has been started already"); } return null; } @Override public void done() { MainFrame.updateProgressBar(-1, 0, 100000, "Idle", true, true); MainFrame.updateProgressBar(-1, 0, 100000, "Idle", false, true); MainFrame.updateTask("Idle...", true); MainFrame.unlockInterface(); } }; worker.execute(); } }); //menuItem.addActionListener(new ActionAdapter(this)); popupMenu.add(menuItem2); MouseListener popupListener = new PopupListener(); jTable1.addMouseListener(popupListener); }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initPopupMenu() { this.getPopupMenu().addSeparator(); JMenuItem resetMenuItem = new JMenuItem("Reset Chart"); resetMenuItem.addActionListener(new ActionListener() { @Override//from w w w. j av a 2s. c o m public void actionPerformed(ActionEvent e) { ChartTab.this.chartPlugin.setInitialized(false); ChartTab.this.chartPlugin.newSwingWorker().execute(); } }); this.getPopupMenu().add(resetMenuItem); JMenuItem updateMenuItem = new JMenuItem("Update Chart Data"); updateMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ChartTab.this.chartPlugin.newSwingWorker().execute(); } }); this.getPopupMenu().add(updateMenuItem); this.getPopupMenu().addSeparator(); }
From source file:com.intuit.tank.proxy.ProxyApp.java
private JPanel getTransactionTable() { JPanel frame = new JPanel(new BorderLayout()); model = new TransactionTableModel(); final JTable table = new TransactionTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);//w w w .j a va 2 s .c o m final JPopupMenu pm = new JPopupMenu(); JMenuItem item = new JMenuItem("Delete Selected"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { int response = JOptionPane.showConfirmDialog(ProxyApp.this, "Are you sure you want to delete " + selectedRows.length + " Transactions?", "Confirm Delete", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { int[] correctedRows = new int[selectedRows.length]; for (int i = selectedRows.length; --i >= 0;) { int row = selectedRows[i]; int index = (Integer) table.getValueAt(row, 0) - 1; correctedRows[i] = index; } Arrays.sort(correctedRows); for (int i = correctedRows.length; --i >= 0;) { int row = correctedRows[i]; Transaction transaction = model.getTransactionForIndex(row); if (transaction != null) { model.removeTransaction(transaction, row); isDirty = true; saveAction.setEnabled(isDirty && !stopAction.isEnabled()); } } } } } }); pm.add(item); table.add(pm); table.addMouseListener(new MouseAdapter() { boolean pressed = false; public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int index = (Integer) table.getValueAt(row, 0) - 1; Transaction transaction = model.getTransactionForIndex(index); if (transaction != null) { detailsTF.setText(transaction.toString()); detailsTF.setCaretPosition(0); detailsDialog.setVisible(true); } } } /** * @{inheritDoc */ @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { pressed = true; int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } /** * @{inheritDoc */ @Override public void mouseReleased(MouseEvent e) { if (!pressed && e.isPopupTrigger()) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } }); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter: "); panel.add(label, BorderLayout.WEST); final JLabel countLabel = new JLabel(" Count: 0 "); panel.add(countLabel, BorderLayout.EAST); final JTextField filterText = new JTextField(""); filterText.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { String text = filterText.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { try { sorter.setRowFilter(RowFilter.regexFilter(text)); countLabel.setText(" Count: " + sorter.getViewRowCount() + " "); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } } }); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); return frame; }
From source file:StocksTable5.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu mFile = new JMenu("File"); mFile.setMnemonic('f'); JMenuItem mData = new JMenuItem("Retrieve Data..."); mData.setMnemonic('r'); ActionListener lstData = new ActionListener() { public void actionPerformed(ActionEvent e) { retrieveData();//from w w w . j a v a2s .co m } }; mData.addActionListener(lstData); mFile.add(mData); mFile.addSeparator(); JMenuItem mExit = new JMenuItem("Exit"); mExit.setMnemonic('x'); ActionListener lstExit = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; mExit.addActionListener(lstExit); mFile.add(mExit); menuBar.add(mFile); return menuBar; }
From source file:JXTransformer.java
public TransformerDemo() { super("Transformer demo"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu lafMenu = new JMenu("LaF"); JMenuItem winLaf = new JMenuItem("Windows LaF"); lafMenu.add(winLaf);/*from w w w . java 2s . c o m*/ winLaf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLaf("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } }); JMenuItem motifLaf = new JMenuItem("Motif LaF"); lafMenu.add(motifLaf); motifLaf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLaf("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); } }); bar.add(lafMenu); JMenuItem metalLaf = new JMenuItem("Metal LaF"); lafMenu.add(metalLaf); metalLaf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLaf("javax.swing.plaf.metal.MetalLookAndFeel"); } }); JMenu settingsMenu = new JMenu("Settings"); settingsMenu.setMnemonic(KeyEvent.VK_S); JMenuItem item = new JMenuItem("Reset sliders", KeyEvent.VK_R); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rotationSlider.setValue(0); scalingSlider.setValue(100); shearingSlider.setValue(0); } }); settingsMenu.add(item); bar.add(settingsMenu); setJMenuBar(bar); JPanel panel = new JPanel(new BorderLayout()); panel.add(createDemoPanel()); panel.add(createStressTestPanel(), BorderLayout.EAST); add(new JScrollPane(panel)); add(new JScrollPane(createToolPanel()), BorderLayout.SOUTH); pack(); }
From source file:com.haulmont.cuba.desktop.App.java
protected Container createStartContentPane() { JPanel pane = new JPanel(new BorderLayout()); menuBar = new JMenuBar(); pane.add(menuBar, BorderLayout.NORTH); Locale loc = Locale.getDefault(); JMenu menu = new JMenu(messages.getMainMessage("mainMenu.file", loc)); menuBar.add(menu);// w ww . j a va 2 s.co m JMenuItem item; item = new JMenuItem(messages.getMainMessage("mainMenu.connect", loc)); item.addActionListener(e -> showLoginDialog()); menu.add(item); item = new JMenuItem(messages.getMainMessage("mainMenu.exit", loc)); item.addActionListener(new ValidationAwareActionListener() { @Override public void actionPerformedAfterValidation(ActionEvent e) { exit(); } }); menu.add(item); if (isTestMode()) { menuBar.setName("startMenu"); } return pane; }
From source file:org.sbml.bargraph.MainWindow.java
/** * Set up menus when running under Windows. *///w w w .j a va2 s . co m public void registerForEvents() { Log.note("Setting up the Windows menus."); JMenuItem fileExitItem = new JMenuItem(); fileExitItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, shortcutKeyMask)); fileExitItem.setMnemonic(java.awt.event.KeyEvent.VK_C); fileExitItem.setText("Exit"); fileExitItem.setToolTipText("Exit application"); fileExitItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { quit(); } }); fileMenu.addSeparator(); fileMenu.add(fileExitItem); JMenu helpMenu = new JMenu(); helpMenu.setText("Help"); JMenuItem aboutMenuItem = new JMenuItem(); aboutMenuItem.setText("About " + Config.APP_NAME); aboutMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { about(); } }); helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); }
From source file:ucar.unidata.idv.control.McVHistogramWrapper.java
/** * Add the default menu items/*from w ww . ja va 2 s . com*/ * * @param items List of menu items * * @return The items list */ @Override public List getPopupMenuItems(List items) { items = super.getPopupMenuItems(items); for (Object o : items) { if (o instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem) o; if ("Properties...".equals(menuItem.getText())) { if (menuItem.getActionListeners().length == 0) { menuItem.setActionCommand(ChartPanel.PROPERTIES_COMMAND); menuItem.addActionListener(buildHistoPropsListener()); } } } } return items; }
From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java
private JMenu createMenuExtra() { final JMenu menuExtra = new JMenu(Messages.getString("Menu.extra")); //$NON-NLS-1$ final JMenuItem menuExtraOpenExternalEditor = new JMenuItem(Messages.getString("Menu.openExternal")); //$NON-NLS-1$ menuExtraOpenExternalEditor.addActionListener(new ActionListener() { @Override//from w w w . j av a 2s. c o m public void actionPerformed(final ActionEvent event) { showExternalEditor(); } }); menuExtra.add(menuExtraOpenExternalEditor); menuExtra.addMenuListener(new MenuListener() { @Override public void menuSelected(final MenuEvent e) { menuExtraOpenExternalEditor.setEnabled(isDefinitionOpen()); } @Override public void menuDeselected(final MenuEvent e) { } @Override public void menuCanceled(final MenuEvent e) { } }); return menuExtra; }