List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem(Action a)
Action
. 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);// ww w . j a v a 2 s . c o m 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:ScreenCapture.java
public ScreenCapture(String title) { super(title); setDefaultCloseOperation(EXIT_ON_CLOSE); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("File"); ActionListener al;//from w ww . j a 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:Main.java
/** * Creates a suitable menu item./*from ww w.ja v a 2 s . c o m*/ * * @param action * @return */ public static JMenuItem createMenuItem(Action action) { final JMenuItem mi; final Boolean selected = (Boolean) action.getValue(Action.SELECTED_KEY); if (selected != null) { mi = new JCheckBoxMenuItem(action); } else { mi = new JMenuItem(action); } mi.setHorizontalTextPosition(JButton.TRAILING); mi.setVerticalTextPosition(JButton.CENTER); return mi; }
From source file:com.bwc.ora.views.LabelPopupMenu.java
private void initMenu() { //determine if the point clicked already has an annotation boolean hasAnnotationAlready = hasAnnoationAlready(); if (hasAnnotationAlready) { //add label to allow users to deselect the label for a given peak JMenuItem nonItem = new JMenuItem("Remove Label"); nonItem.addActionListener(e -> { removeAnnotation();// ww w . j a va 2s . com lrp.setAnnotations(LrpDisplayFrame.getInstance().getAnnotations()); }); add(nonItem); } //add list of possible labels for a point to the popup menu Arrays.stream(RetinalBand.values()).map(RetinalBand::toString).map(label -> { XYPointerAnnotation pointer = new XYPointerAnnotation(label, item.getDataset().getXValue(item.getSeriesIndex(), item.getItem()), item.getDataset().getYValue(item.getSeriesIndex(), item.getItem()), 0); pointer.setBaseRadius(35.0); pointer.setTipRadius(10.0); pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); pointer.setPaint(Color.blue); pointer.setTextAnchor(TextAnchor.CENTER_LEFT); JMenuItem l = new JMenuItem(label); l.addActionListener(e -> { if (hasAnnotationAlready) { removeAnnotation(); } chartPanel.getChart().getXYPlot().addAnnotation(pointer); lrp.setAnnotations(LrpDisplayFrame.getInstance().getAnnotations()); }); return l; }).forEach(this::add); }
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);//from w w w. ja v a2 s . co m 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:fr.crnan.videso3d.ihm.TrajectoryProjectionGUI.java
public TrajectoryProjectionGUI(List<VidesoTrack> tracks, Globe globe) { JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w w w.ja v a 2 s. c o m*/ JMenu mnParamtres = new JMenu("Paramtres"); menuBar.add(mnParamtres); JMenuItem mntmNewMenuItem = new JMenuItem("New menu item"); mnParamtres.add(mntmNewMenuItem); double ref = TracksStatsProducer.computeReferenceAltitude(tracks); XYSeriesCollection dataset = new XYSeriesCollection(); for (VidesoTrack t : tracks) { dataset.addSeries(TracksStatsProducer.computeDevelopedPath(t, ref, false, globe)); } JFreeChart chart = ChartFactory.createXYLineChart("Projection", "Distance (NM)", "Altitude (FL)", dataset, PlotOrientation.VERTICAL, false, true, false); ChartPanel panel = new ChartPanel(chart); setContentPane(panel); pack(); }
From source file:Main.java
public Main(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); tabComponentsItem = new JCheckBoxMenuItem("Use TabComponents", true); tabComponentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK)); tabComponentsItem.addActionListener(e -> { for (int i = 0; i < pane.getTabCount(); i++) { if (tabComponentsItem.isSelected()) { } else { pane.setTabComponentAt(i, null); }/*from www. j ava 2 s . com*/ } }); scrollLayoutItem = new JCheckBoxMenuItem("Set ScrollLayout"); scrollLayoutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK)); scrollLayoutItem.addActionListener(e -> { if (pane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT) { pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } else { pane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT); } }); JMenuItem resetItem = new JMenuItem("Reset JTabbedPane"); resetItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK)); resetItem.addActionListener(e -> runTest()); JMenu optionsMenu = new JMenu("Options"); optionsMenu.add(tabComponentsItem); optionsMenu.add(scrollLayoutItem); optionsMenu.add(resetItem); menuBar.add(optionsMenu); setJMenuBar(menuBar); add(pane); }
From source file:com.codedx.burp.ContextMenuFactory.java
@Override public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) { if (invocation.getInvocationContext() == IContextMenuInvocation.CONTEXT_SCANNER_RESULTS) { List<JMenuItem> lst = new ArrayList<JMenuItem>(); JMenuItem export = new JMenuItem("Send to Code Dx"); export.addActionListener(new ContextMenuActionListener(burpExtender, callbacks, invocation)); lst.add(export);// w w w . jav a 2s .c o m return lst; } return null; }
From source file:Main.java
private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(x, y); if (path == null) return;/*from ww w . j ava 2 s . c o m*/ DefaultMutableTreeNode rightClickedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); TreePath[] selectionPaths = tree.getSelectionPaths(); boolean isSelected = false; if (selectionPaths != null) { for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(path)) { isSelected = true; } } } if (!isSelected) { tree.setSelectionPath(path); } if (rightClickedNode.isLeaf()) { JPopupMenu popup = new JPopupMenu(); final JMenuItem refreshMenuItem = new JMenuItem("refresh"); refreshMenuItem.addActionListener(ev -> System.out.println("refresh!")); popup.add(refreshMenuItem); popup.show(tree, x, y); } }
From source file:OptPaneComparison.java
public OptPaneComparison(final String message) { setDefaultCloseOperation(EXIT_ON_CLOSE); final int msgType = JOptionPane.QUESTION_MESSAGE; final int optType = JOptionPane.OK_CANCEL_OPTION; final String title = message; setSize(350, 200);//from w w w. j a v a2 s .co m // Create a desktop for internal frames final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); // Add a simple menu bar JMenuBar mb = new JMenuBar(); setJMenuBar(mb); JMenu menu = new JMenu("Dialog"); JMenu imenu = new JMenu("Internal"); mb.add(menu); mb.add(imenu); final JMenuItem construct = new JMenuItem("Constructor"); final JMenuItem stat = new JMenuItem("Static Method"); final JMenuItem iconstruct = new JMenuItem("Constructor"); final JMenuItem istat = new JMenuItem("Static Method"); menu.add(construct); menu.add(stat); imenu.add(iconstruct); imenu.add(istat); // Create our JOptionPane. We're asking for input, so we call // setWantsInput. // Note that we cannot specify this via constructor parameters. optPane = new JOptionPane(message, msgType, optType); optPane.setWantsInput(true); // Add a listener for each menu item that will display the appropriate // dialog/internal frame construct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JDialog d = optPane.createDialog(desk, title); d.setVisible(true); respond(getOptionPaneValue()); } }); stat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInputDialog(desk, message, title, msgType); respond(s); } }); iconstruct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JInternalFrame f = optPane.createInternalFrame(desk, title); f.setVisible(true); // Listen for the frame to close before getting the value from // it. f.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) && (ev.getNewValue() == Boolean.TRUE)) { respond(getOptionPaneValue()); } } }); } }); istat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType); respond(s); } }); }