You may (or may not) also find this article informative.
P.S Don't forget to use code tags when posting code.
P.S Don't forget to use code tags when posting code.
popup.show(this, 30, 10);
popup.show(this, 30, 10);
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Popup extends JPanel implements ActionListener { private JButton jcomp1; JPopupMenu popup = new JPopupMenu(); //Up a=new Up(); public Popup() { //construct components jcomp1 = new JButton ("Button 1"); //adjust size and set layout setPreferredSize (new Dimension (150, 63)); setLayout (null); //add components add (jcomp1); //set component bounds (only needed by Absolute Positioning) jcomp1.setBounds (10, 15, 100, 20); JMenuItem menuItem; //Create the popup menu. menuItem = new JMenuItem("A popup menu item"); jcomp1.addActionListener(this); popup.add(menuItem); menuItem = new JMenuItem("Another popup menu item"); popup.add(menuItem); } public void actionPerformed(ActionEvent e) { popup.show(this, 30, 10); } public static void main (String[] args) { JFrame frame = new JFrame ("MyPanel"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add (new Popup()); frame.pack(); frame.setVisible (true); } }
Comment