Example usage for javax.swing JMenuItem addActionListener

List of usage examples for javax.swing JMenuItem addActionListener

Introduction

In this page you can find the example usage for javax.swing JMenuItem addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:org.simbrain.plot.barchart.BarChartGui.java

/**
 * Creates the menu bar./*w  w w  .  j ava2s .  c om*/
 */
private void createAttachMenuBar() {
    JMenuBar bar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");
    for (Action action : actionManager.getOpenSavePlotActions()) {
        fileMenu.add(action);
    }
    fileMenu.addSeparator();
    fileMenu.add(new CloseAction(this.getWorkspaceComponent()));

    JMenu editMenu = new JMenu("Edit");
    JMenuItem preferences = new JMenuItem("Preferences...");
    preferences.addActionListener(this);
    preferences.setActionCommand("dialog");
    editMenu.add(preferences);

    JMenu helpMenu = new JMenu("Help");
    ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/bar_chart.html");
    JMenuItem helpItem = new JMenuItem(helpAction);
    helpMenu.add(helpItem);

    bar.add(fileMenu);
    bar.add(editMenu);
    bar.add(helpMenu);

    getParentFrame().setJMenuBar(bar);
}

From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderConnectionInfo.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");
    JMenuItem item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.HIDE_INFO_CONNECTION));
    item.setActionCommand(HIDE_CONNECTION_INFO);
    item.addActionListener(this);
    menu.add(item);/*from w w  w .  ja  v a  2 s  .com*/

    //        menu.addSeparator();
    //
    //        JMenuItem item2 = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.IMPLIED));
    //        item2.setActionCommand(SET_IMPLIED);
    //        item2.addActionListener(this);
    //        menu.add(item2);

}

From source file:Java2DExample.java

public Java2DExample() {
    super("Java 2D Image Processing Demo");
    imagePanel = new ImagePanel(Java2DExample.class.getResource("yourImage.png"));

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);//w  w  w  .  j  a va2 s. c  om
    filterMenu.setMnemonic('I');

    JMenuItem originalMenuItem = new JMenuItem("Display Original");
    originalMenuItem.setMnemonic('O');

    originalMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent action) {
            imagePanel.displayOriginalImage();
        }

    });

    JMenuItem invertMenuItem = createMenuItem("Invert", 'I', invertFilter);
    JMenuItem sharpenMenuItem = createMenuItem("Sharpen", 'S', sharpenFilter);
    JMenuItem blurMenuItem = createMenuItem("Blur", 'B', blurFilter);
    JMenuItem changeColorsMenuItem = createMenuItem("Change Colors", 'C', colorFilter);

    filterMenu.add(originalMenuItem);
    filterMenu.add(invertMenuItem);
    filterMenu.add(sharpenMenuItem);
    filterMenu.add(blurMenuItem);
    filterMenu.add(changeColorsMenuItem);

    menuBar.add(filterMenu);

    getContentPane().add(imagePanel, BorderLayout.CENTER);

}

From source file:Main.java

protected void showMenu(int x, int y) {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem mi = new JMenuItem("Delete");
    TreePath path = tree.getSelectionPath();
    Object node = path.getLastPathComponent();
    if (node == tree.getModel().getRoot()) {
        mi.setEnabled(false);//  ww  w  .ja v a 2  s.com
    }
    popup.add(mi);
    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            deleteSelectedItems();
        }
    });
    popup.show(tree, x, y);
}

From source file:Main.java

public JMenuBar createMenuBar() {
    JMenuBar top_menu_bar = new JMenuBar();
    JMenu main_menu = new JMenu("Menu");
    main_menu.setMnemonic(KeyEvent.VK_M);
    top_menu_bar.add(main_menu);//from ww  w.j  a  v  a 2s  .  c om
    JMenuItem menu_item;

    menu_item = new JMenuItem("Add New");
    menu_item.setMnemonic(KeyEvent.VK_N);
    menu_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
    menu_item.setActionCommand("new");
    menu_item.addActionListener(e -> createThumb());
    main_menu.add(menu_item);
    return top_menu_bar;
}

From source file:org.simbrain.plot.scatterplot.ScatterPlotGui.java

/**
 * Creates the menu bar.//  www  . ja v a  2  s .c  o m
 */
private void createAttachMenuBar() {
    JMenuBar bar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");
    for (Action action : actionManager.getOpenSavePlotActions()) {
        fileMenu.add(action);
    }
    fileMenu.addSeparator();
    fileMenu.add(new CloseAction(this.getWorkspaceComponent()));

    JMenu editMenu = new JMenu("Edit");
    JMenuItem preferences = new JMenuItem("Preferences...");
    preferences.addActionListener(this);
    preferences.setActionCommand("dialog");
    editMenu.add(preferences);

    JMenu helpMenu = new JMenu("Help");
    ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/scatter_plot.html");
    JMenuItem helpItem = new JMenuItem(helpAction);
    helpMenu.add(helpItem);

    bar.add(fileMenu);
    bar.add(editMenu);
    bar.add(helpMenu);

    getParentFrame().setJMenuBar(bar);
}

From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderConnectionSpicy.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");
    JMenuItem item;
    item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.SHOW_HIDE_INFO_CONNECTION));
    item.setActionCommand(SHOW);//from w  w  w .  java 2s  . c  o m
    item.addActionListener(this);
    menu.add(item);
    item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_CONNECTION));
    item.setActionCommand(DELETE);
    item.addActionListener(this);
    menu.add(item);
}

From source file:hudson.lifecycle.WindowsSlaveInstaller.java

public Void call() {
    if (File.separatorChar == '/')
        return null; // not Windows
    if (System.getProperty("hudson.showWindowsServiceInstallLink") == null)
        return null; // only show this when it makes sense, which is when we run from JNLP

    dialog = MainDialog.get();//from   www .  ja  va  2  s . c o  m
    if (dialog == null)
        return null; // can't find the main window. Maybe not running with GUI

    // capture the engine
    engine = Engine.current();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            MainMenu mainMenu = dialog.getMainMenu();
            JMenu m = mainMenu.getFileMenu();
            JMenuItem menu = new JMenuItem(Messages.WindowsInstallerLink_DisplayName(), KeyEvent.VK_W);
            menu.addActionListener(WindowsSlaveInstaller.this);
            m.add(menu);
            mainMenu.commit();
        }
    });

    return null;
}

From source file:it.unibas.spicygui.controllo.provider.composition.MyPopupProviderConnectionMergeComposition.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");
    JMenuItem item;

    item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_CONNECTION));
    item.setActionCommand(DELETE);//w w  w . ja v a 2s  .c  om
    item.addActionListener(this);

    menu.add(item);
}

From source file:ImageProcessingTest.java

public ImageProcessingFrame() {
    setTitle("ImageProcessingTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    add(new JComponent() {
        public void paintComponent(Graphics g) {
            if (image != null)
                g.drawImage(image, 0, 0, null);
        }// w ww . j ava2  s .c o  m
    });

    JMenu fileMenu = new JMenu("File");
    JMenuItem openItem = new JMenuItem("Open");
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            openFile();
        }
    });
    fileMenu.add(openItem);

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
    fileMenu.add(exitItem);

    JMenu editMenu = new JMenu("Edit");
    JMenuItem blurItem = new JMenuItem("Blur");
    blurItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float weight = 1.0f / 9.0f;
            float[] elements = new float[9];
            for (int i = 0; i < 9; i++)
                elements[i] = weight;
            convolve(elements);
        }
    });
    editMenu.add(blurItem);

    JMenuItem sharpenItem = new JMenuItem("Sharpen");
    sharpenItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 5.f, -1.0f, 0.0f, -1.0f, 0.0f };
            convolve(elements);
        }
    });
    editMenu.add(sharpenItem);

    JMenuItem brightenItem = new JMenuItem("Brighten");
    brightenItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float a = 1.1f;
            // float b = 20.0f;
            float b = 0;
            RescaleOp op = new RescaleOp(a, b, null);
            filter(op);
        }
    });
    editMenu.add(brightenItem);

    JMenuItem edgeDetectItem = new JMenuItem("Edge detect");
    edgeDetectItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 4.f, -1.0f, 0.0f, -1.0f, 0.0f };
            convolve(elements);
        }
    });
    editMenu.add(edgeDetectItem);

    JMenuItem negativeItem = new JMenuItem("Negative");
    negativeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            short[] negative = new short[256 * 1];
            for (int i = 0; i < 256; i++)
                negative[i] = (short) (255 - i);
            ShortLookupTable table = new ShortLookupTable(0, negative);
            LookupOp op = new LookupOp(table, null);
            filter(op);
        }
    });
    editMenu.add(negativeItem);

    JMenuItem rotateItem = new JMenuItem("Rotate");
    rotateItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (image == null)
                return;
            AffineTransform transform = AffineTransform.getRotateInstance(Math.toRadians(5),
                    image.getWidth() / 2, image.getHeight() / 2);
            AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);
            filter(op);
        }
    });
    editMenu.add(rotateItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    setJMenuBar(menuBar);
}