List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem(Action a)
Action
. From source file:MouseTest.java
public MouseTest() { super();/*from w w w .j a va 2s . co m*/ final JPopupMenu pop = new JPopupMenu(); pop.add(new JMenuItem("Cut")); pop.add(new JMenuItem("Copy")); pop.add(new JMenuItem("Paste")); pop.addSeparator(); pop.add(new JMenuItem("Select All")); pop.setInvoker(this); MouseListener popup = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } private void showPopup(MouseEvent e) { pop.show(e.getComponent(), e.getX(), e.getY()); } }; addMouseListener(popup); MouseListener drawing1 = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { color = Color.RED; startX = endX = e.getX(); startY = endY = e.getY(); repaint(); } public void mouseReleased(MouseEvent e) { color = Color.BLACK; repaint(); } }; addMouseListener(drawing1); MouseMotionListener drawing2 = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { endX = e.getX(); endY = e.getY(); repaint(); } public void mouseMoved(MouseEvent e) { } }; addMouseMotionListener(drawing2); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);/*from www . j ava2 s . c om*/ menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); JPopupMenu pop = menu.getPopupMenu(); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);// w w w . j a va 2 s . co m menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); MenuListener[] c = menu.getMenuListeners(); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);/*from w ww. j ava2 s.co m*/ menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); AccessibleContext ac = menu.getAccessibleContext(); }
From source file:ImageViewer.java
public ImageViewer() { setTitle("ImageViewer"); setSize(300, 400);/*from www.j ava 2 s . com*/ JMenuBar mbar = new JMenuBar(); JMenu m = new JMenu("File"); openItem = new JMenuItem("Open"); openItem.addActionListener(this); m.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); m.add(exitItem); mbar.add(m); setJMenuBar(mbar); label = new JLabel(); Container contentPane = getContentPane(); contentPane.add(label, "Center"); }
From source file:FileChooserDemo.java
public FileChooserDemo() { setTitle("ZipTest"); setSize(300, 400);//from ww w. java 2 s.co m JMenuBar mbar = new JMenuBar(); JMenu m = new JMenu("File"); openItem = new JMenuItem("Open"); openItem.addActionListener(this); m.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); m.add(exitItem); mbar.add(m); Container contentPane = getContentPane(); contentPane.add(mbar, "North"); }
From source file:FramewithAboutMenu.java
public FramewithAboutMenu(String title) { JMenuBar menuBar = new JMenuBar(); setTitle(title);//from w w w . ja va 2 s . co m setJMenuBar(menuBar); setDefaultCloseOperation(EXIT_ON_CLOSE); JMenu fileMenu = new JMenu("File"); JMenu elementMenu = new JMenu("Elements"); JMenu helpMenu = new JMenu("Help"); fileMenu.setMnemonic('F'); elementMenu.setMnemonic('E'); helpMenu.setMnemonic('H'); JMenuItem aboutItem = new JMenuItem("About"); helpMenu.add(aboutItem); menuBar.add(helpMenu); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);// w w w . j a va2s. c o m menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.insert(new JMenuItem("Exit"), 0); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);/*from ww w .jav a2 s . c om*/ menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.isSelected(); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);/* w w w . ja v a 2 s. c o m*/ menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.insert("Exit", 0); }