J
Justin
hello again, havin a bitchin time with this popup menu I'm trying to
create. I'm a learn by doing type of person and I havent found any
good examples of how to implement a pop-up menu. The main class in the
application extends a JPanel. I searched google and found the
following snippet of code and inserted it into my constructor:
final JPopupMenu menu = new JPopupMenu();
// Create and add a menu item
JMenuItem item = new JMenuItem("Item Label");
item.addActionListener(this);
menu.add(item);
// Set the component to show the popup menu
this.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
public void mouseReleased(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
});
however, this code does nothing when I run the application. Currently,
my actionPerformed method is empty, I dont know if I have to add
anything to this method to get the popup to run or not. I'll give it a
try, but any help would be appreciated.
create. I'm a learn by doing type of person and I havent found any
good examples of how to implement a pop-up menu. The main class in the
application extends a JPanel. I searched google and found the
following snippet of code and inserted it into my constructor:
final JPopupMenu menu = new JPopupMenu();
// Create and add a menu item
JMenuItem item = new JMenuItem("Item Label");
item.addActionListener(this);
menu.add(item);
// Set the component to show the popup menu
this.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
public void mouseReleased(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
});
however, this code does nothing when I run the application. Currently,
my actionPerformed method is empty, I dont know if I have to add
anything to this method to get the popup to run or not. I'll give it a
try, but any help would be appreciated.