List of usage examples for javax.swing JButton setComponentPopupMenu
@BeanProperty(preferred = true, description = "Popup to show") public void setComponentPopupMenu(JPopupMenu popup)
JPopupMenu
for this JComponent
. From source file:PopupSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("PopupSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create popup menu, attach popup menu listener JPopupMenu popupMenu = new JPopupMenu("Title"); // Cut/*from w ww .ja v a2s . c o m*/ JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem); // Copy JMenuItem copyMenuItem = new JMenuItem("Copy"); popupMenu.add(copyMenuItem); // Paste JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findMenuItem = new JMenuItem("Find"); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MyPopupMenuListener.java
public static void main(final String args[]) { JFrame frame = new JFrame("Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPopupMenu popupMenu = new JPopupMenu("Title"); PopupMenuListener popupMenuListener = new MyPopupMenuListener(); popupMenu.addPopupMenuListener(popupMenuListener); JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem);/*from ww w.j av a2s . c o m*/ JMenuItem copyMenuItem = new JMenuItem("Copy"); popupMenu.add(copyMenuItem); JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); popupMenu.addSeparator(); JMenuItem findMenuItem = new JMenuItem("Find"); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:PopupActionListener.java
public static void main(final String args[]) { JFrame frame = new JFrame("PopupSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create popup menu, attach popup menu listener JPopupMenu popupMenu = new JPopupMenu("Title"); ActionListener actionListener = new PopupActionListener(); // Cut// ww w .j a va 2 s . c om JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem); // Copy JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(actionListener); popupMenu.add(copyMenuItem); // Paste JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.addActionListener(actionListener); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findMenuItem = new JMenuItem("Find"); findMenuItem.addActionListener(actionListener); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MyPopupMenuListener.java
public static void main(final String args[]) { JFrame frame = new JFrame("PopupSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create popup menu, attach popup menu listener JPopupMenu popupMenu = new JPopupMenu("Title"); PopupMenuListener popupMenuListener = new MyPopupMenuListener(); popupMenu.addPopupMenuListener(popupMenuListener); // Cut/*from ww w . j a v a2 s .c o m*/ JMenuItem cutMenuItem = new JMenuItem("Cut"); popupMenu.add(cutMenuItem); // Copy JMenuItem copyMenuItem = new JMenuItem("Copy"); popupMenu.add(copyMenuItem); // Paste JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); // Separator popupMenu.addSeparator(); // Find JMenuItem findMenuItem = new JMenuItem("Find"); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new PopupActionListener(); PopupMenuListener popupMenuListener = new MyPopupMenuListener(); JPopupMenu popupMenu = new JPopupMenu("Title"); popupMenu.addPopupMenuListener(popupMenuListener); JMenuItem cutMenuItem = new JMenuItem("Cut"); cutMenuItem.addActionListener(actionListener); popupMenu.add(cutMenuItem);/*from www . j a v a 2s . com*/ JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(actionListener); popupMenu.add(copyMenuItem); JMenuItem pasteMenuItem = new JMenuItem("Paste"); pasteMenuItem.addActionListener(actionListener); pasteMenuItem.setEnabled(false); popupMenu.add(pasteMenuItem); popupMenu.addSeparator(); JMenuItem findMenuItem = new JMenuItem("Find"); findMenuItem.addActionListener(actionListener); popupMenu.add(findMenuItem); JButton label = new JButton(); frame.add(label); label.setComponentPopupMenu(popupMenu); frame.setSize(350, 250); frame.setVisible(true); }