Results 1 to 4 of 4
  1. #1
    sylvievdb is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default 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.
    Java 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.
    Java 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?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,558
    Rep Power
    23

    Default

    Use the show method vs setVisible

  3. #3
    sylvievdb is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default

    I didn't use the show method because it is deprecated. Isn't setVisible the alternative?

    Greetz

  4. #4
    sylvievdb is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default

    Ok, you meant this one: show(Component invoker, int x, int y)

    Thanks

Similar Threads

  1. JPopupMenu
    By hungleon88 in forum NetBeans
    Replies: 8
    Last Post: 01-15-2009, 05:00 PM
  2. JPopupMenu falls behind window
    By undertow in forum AWT / Swing
    Replies: 4
    Last Post: 01-17-2008, 10:20 PM
  3. dynamising the height of a JPopupMenu
    By iimasd in forum AWT / Swing
    Replies: 6
    Last Post: 11-21-2007, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •