Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 920425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:42:41+00:00 2026-05-15T18:42:41+00:00

I have create a popup menu and on right click in a panel the

  • 0

I have create a popup menu and on right click in a panel the menu is displayed. But when i click the menu item the checkbox doesnt get selected.
Here is the code:

public class DebugMenu extends JPopupMenu implements ActionListener{

public void actionPerformed(ActionEvent e) {
    System.out.println("inside action");
      AbstractButton aButton = (AbstractButton) e.getSource();
      System.out.println(aButton.getText() +" " +aButton.getModel().isSelected());
      aButton.getModel().setSelected(!aButton.getModel().isSelected());
}

public DebugMenu(){
    JMenuItem menuItem = new JCheckBoxMenuItem("2");

    add(menuItem);
    menuItem.addActionListener(this);
    menuItem = new JCheckBoxMenuItem("1");
    add(menuItem);
    menuItem.addActionListener(this);
}

}

And the Panel class

public class TestPanel implements MouseListener{

public TestPanel(){
    JFrame frame = new JFrame("TEST");
    frame.setSize(400,400);
    frame.addMouseListener(TestPanel.this);
    frame.setVisible(true); 
}

public static void main(String args[]){
    new TestPanel();


}

public void mouseReleased(MouseEvent e) {
    DebugMenu menu = new DebugMenu();
     if(e.isPopupTrigger()){
         System.out.println("trigger");
         menu.show(e.getComponent(), e.getX(), e.getY());
     }              
}

public void mousePressed(MouseEvent e) {
    DebugMenu menu = new DebugMenu();
     if(e.isPopupTrigger()){
         System.out.println("trigger");
         menu.show(e.getComponent(), e.getX(), e.getY());
     }


}

public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent e) {
    // TODO Auto-generated method stub

}

public void mouseClicked(MouseEvent e) {
    DebugMenu menu = new DebugMenu();
     if(e.isPopupTrigger()){
         menu.show(e.getComponent(), e.getX(), e.getY());
     }

}

}

what i am doing wrong ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:42:42+00:00Added an answer on May 15, 2026 at 6:42 pm

    I figured it out … I should not be creating the DebugMenu object inside the mouseEvents…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a control that creates a popup menu on right click, and I
When I right-click in my class library, I get some quick options to create
I have a function that opens a popup menu. but on safari and Chrome
I need to provide right-click popup context menu support for a cell in a
The sample code below (heavily influenced from here ) has a right-click context menu
I'm trying to create an option menu in my preferences but I can't get
I have create my own NSOpenGLView class, right now the data that i want
I have create web app in MVS 3 but failed to display alert message
I have create a widget in android , whenever i click on Widget TextView
I want to create a simple eclipse plugin, which does: When you right click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.