-
JPopupMenu problem
I have a problem with my JPopupMenu. I have no problem opening it. There is even no problem using it. The menu-items react on the action. But when a menu-item is clicked, normally, the background automatically changes color. In my case, that doesn't happen. Can anyone help?
This is my popupmenu.
Code:
public class JOrderPopupMenu extends JPopupMenu implements ActionListener{
private JMenuItem mniMemo;
private JMenuItem mniNosRef;
public JOrderPopupMenu(){
mniMemo = new JMenuItem("Memo");
mniNosRef = new JMenuItem("No_Stock_Referentie");
mniMemo.addActionListener(this);
mniNosRef.addActionListener(this);
JCheckBoxMenuItem test = new JCheckBoxMenuItem("test");
add(mniMemo);
add(mniNosRef);
add(test);
}
public void actionPerformed(ActionEvent e) {
System.out.println("actionPerformed");
if( (JMenuItem)e.getSource() == mniMemo){
System.out.println("mniMemo");
}
else if ((JMenuItem) e.getSource() == mniNosRef){
System.out.println("mniNosRef");
}
}
}
This is how I tested it.
Code:
public class TestPopup extends JPanel implements MouseListener{
private JOrderPopupMenu jOrderPopupMenu;
public TestPopup(){
JButton btnTest = new JButton("Test");
btnTest.addMouseListener(this);
add(btnTest);
jOrderPopupMenu = new JOrderPopupMenu();
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setContentPane(new TestPopup());
frame.pack();
frame.setVisible(true);
}
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void mouseReleased(MouseEvent e) {
if(e.isPopupTrigger()){
jOrderPopupMenu.setVisible(true);
}
}
}
Can anyone help?
-
Use the show method vs setVisible
-
I didn't use the show method because it is deprecated. Isn't setVisible the alternative?
Greetz
-
Ok, you meant this one: show(Component invoker, int x, int y)
Thanks