List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:grafix.telas.componentes.GrafixChartMouseListener.java
private void criarPopupMenu() { popup = new JPopupMenu(); JMenuItem menuItem; menuItem = new JMenuItem("Configurar janela..."); menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "config.gif")); menuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { abrirFormConfiguracoes(-1);/*from ww w . j a va2s . co m*/ } }); popup.add(menuItem); menuItem = new JMenuItem("Configurar grfico..."); menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "configurar3.gif")); menuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { abrirFormConfiguracoes(plotClicado); } }); popup.add(menuItem); menuItem = new JMenuItem("ndices..."); menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "indices.gif")); menuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { abrirFormIndices(plotClicado); } }); popup.add(menuItem); }
From source file:it.unibas.spicygui.controllo.provider.intermediatezone.MyPopupProviderConnectionFunctionalDep.java
private void createPopupMenu() { menu = new JPopupMenu("Popup menu"); JMenuItem item; item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_CONNECTION)); item.setActionCommand(DELETE);//from ww w .ja v a 2 s . c o m item.addActionListener(this); menu.add(item); }
From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java
private void initMenu() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/*from w w w .ja v a 2 s . c o m*/ JMenuItem open = new JMenuItem("Open Project Folder", KeyEvent.VK_O); open.setMnemonic(KeyEvent.VK_O); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptForGradleBaseDir(); refresh(); } }); fileMenu.add(open); JMenuItem refresh = new JMenuItem("Refresh"); refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { refresh(); } }); fileMenu.add(refresh); fileMenu.addSeparator(); JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X); exit.setMnemonic(KeyEvent.VK_X); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exit); setJMenuBar(menuBar); }
From source file:org.broad.igv.peaks.PeakTrackMenu.java
private void init(final TrackClickEvent trackClickEvent) { Collection<Track> tracks = IGV.getInstance().getSelectedTracks(); //Arrays.asList(new Track[] {track}); //Title/*from w ww. j a v a 2 s . c om*/ JLabel popupTitle = new JLabel("<html><b>" + track.getName(), JLabel.LEFT); Font newFont = getFont().deriveFont(Font.BOLD, 12); popupTitle.setFont(newFont); add(popupTitle); addSeparator(); add(TrackMenuUtils.getTrackRenameItem(tracks)); add(TrackMenuUtils.getChangeTrackHeightItem(tracks)); add(TrackMenuUtils.getChangeFontSizeItem(tracks)); //Change Track Settings addDisplayModeItems(); addSeparator(); JMenuItem plotItem = new JMenuItem("Open Trend Plot..."); plotItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { openTimeSeriesPlot(trackClickEvent); } }); add(plotItem); if (track.isShowSignals()) { add(TrackMenuUtils.getDataRangeItem(tracks)); add(TrackMenuUtils.getLogScaleItem(tracks)); add(TrackMenuUtils.getShowDataRangeItem(tracks)); } addSeparator(); add(TrackMenuUtils.getRemoveMenuItem(tracks)); }
From source file:de.genvlin.plugins.jfreechart.JFreeChartPluginImpl.java
public void sendRequest(RequestEvent ri) { if (ri.getActionContextReason() == PluginPool.SELECTED_COLS) { selected = (VectorInterface[]) ((GTablePanel) ri.getSource()).getSelectedVectors(); JMenu menu = new JMenu(getName()); JMenuItem item = new JMenuItem(getMenuName()); item.setActionCommand(getMenuName()); menu.add(item);/*from www .j a v a 2s .c o m*/ item.addActionListener(this); item = new JMenuItem(LINEAR_REG); item.setActionCommand(LINEAR_REG); menu.add(item); item.addActionListener(this); ((JPopupMenu) ri.getObject()).add(menu); } }
From source file:FillViewportHeightDemo.java
public FillViewportHeightDemo() { super("Empty Table DnD Demo"); tableModel = getDefaultTableModel(); table = new JTable(tableModel); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDropMode(DropMode.INSERT_ROWS); table.setTransferHandler(new TransferHandler() { public boolean canImport(TransferSupport support) { // for the demo, we'll only support drops (not clipboard paste) if (!support.isDrop()) { return false; }/*w w w . j a va 2 s . co m*/ // we only import Strings if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } return true; } public boolean importData(TransferSupport support) { // if we can't handle the import, say so if (!canImport(support)) { return false; } // fetch the drop location JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); int row = dl.getRow(); // fetch the data and bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (IOException e) { return false; } String[] rowData = data.split(","); tableModel.insertRow(row, rowData); Rectangle rect = table.getCellRect(row, 0, false); if (rect != null) { table.scrollRectToVisible(rect); } // demo stuff - remove for blog model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); // end demo stuff return true; } }); JList dragFrom = new JList(model); dragFrom.setFocusable(false); dragFrom.setPrototypeCellValue(getNextString(100)); model.insertElementAt(getNextString(count++), 0); dragFrom.setDragEnabled(true); dragFrom.setBorder(BorderFactory.createLoweredBevelBorder()); dragFrom.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) { String text = (String) model.getElementAt(0); String[] rowData = text.split(","); tableModel.insertRow(table.getRowCount(), rowData); model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); } } }); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); JPanel wrap = new JPanel(); wrap.add(new JLabel("Drag from here:")); wrap.add(dragFrom); p.add(Box.createHorizontalStrut(4)); p.add(Box.createGlue()); p.add(wrap); p.add(Box.createGlue()); p.add(Box.createHorizontalStrut(4)); getContentPane().add(p, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(table); getContentPane().add(sp, BorderLayout.CENTER); fillBox = new JCheckBoxMenuItem("Fill Viewport Height"); fillBox.addActionListener(this); JMenuBar mb = new JMenuBar(); JMenu options = new JMenu("Options"); mb.add(options); setJMenuBar(mb); JMenuItem clear = new JMenuItem("Reset"); clear.addActionListener(this); options.add(clear); options.add(fillBox); getContentPane().setPreferredSize(new Dimension(260, 180)); }
From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java
private void assignCommand(final JMenuItem jMenuItem, MenuItem item) { final MenuCommand command = new MenuCommand(item); jMenuItem.addActionListener(new ValidationAwareActionListener() { @Override/* www. j av a 2 s . c om*/ public void actionPerformedAfterValidation(ActionEvent e) { command.execute(); StringBuilder menuPath = new StringBuilder(); formatMenuPath(item, menuPath); userActionsLog.trace("Action \"{}\" was performed using menu item {}", command.getCommandDescription(), menuPath.toString()); } }); }
From source file:edu.gcsc.vrl.jfreechart.JFXPlotContainerType.java
protected void updateChartPanel(Container container, final JFreeChart jFreeChart) { if (chartPanel != null) { chartContainer.remove(chartPanel); }//w w w .j av a 2 s . c om chartPanel = new ChartPanel(jFreeChart); chartContainer.add(chartPanel); JPopupMenu menu = chartPanel.getPopupMenu(); menu.addSeparator(); JMenuItem item1 = new JMenuItem("Export"); item1.setActionCommand("export_chart"); item1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("export_chart")) { try { new JFExport().openExportDialog(jFreeChart); } catch (Exception e1) { e1.printStackTrace(System.err); } } } }); menu.add(item1); revalidate(); }
From source file:sturesy.voting.gui.VotingEvaluationPanelUI.java
/** * creates a new ChartPanel inside this UI * /*w w w. j ava2 s . c o m*/ * @param categoryDataset * the Data * @param questionText * the questiontext to display above * @param background * background color * @param showAnswers * highlight correct answer in green? * @param correctAnswer * index of correct answer * @param showPercent * should it show percent values or absolute values? */ public void createNewChartPanel(CategoryDataset categoryDataset, String questionText, Color background, boolean showAnswers, List<Integer> correctAnswers, boolean showPercent) { JFreeChart chart = createChart(categoryDataset, questionText, background, showAnswers, correctAnswers, showPercent); ChartPanel chartPanel = new ChartPanel(chart); setNewChartPanel(chartPanel); String menuItemText = Localize .getString(showPercent ? "label.jfreechart.switch.absolute" : "label.jfreechart.switch.percent"); JMenuItem menuItem = new JMenuItem(menuItemText); chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(menuItem); menuItem.addActionListener(_menuItemActionListener); }
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.j av a 2s . c om 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); }