Solved

JPopupMenu not showing up

Posted on 2003-11-19
12
402 Views
Last Modified: 2012-05-05
I have a class that extends JPopupMenu (called extendedPopupMenu). References are passed all over the place so posting code is kind of difficult.

When I do [instance].toString();
the following is generated....

extendedPopupMenu[,0,0,0x0,invalid,layout=javax.swing.plaf.basic.DefaultMenuLayout,
alignmentX=null,alignmentY=null,border=javax.swing.plaf.metal.MetalBorders$PopupMenuBorder
@29ce8c,flags=8,maximumSize=,minimumSize=,preferredSize=,desiredLocationX=0,desiredLocationY=0,
label=,lightWeightPopupEnabled=true,margin=,paintBorder=true]

My problem is the menu wont show up. Could someone please tell me if anything here is noticably wrong?
0
Comment
Question by:illucid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9784827
> My problem is the menu wont show up.

post the code that pops it up.
0
 

Author Comment

by:illucid
ID: 9784851

                  private void maybeShowPopup(MouseEvent e) {
                        if (e.isPopupTrigger()) {
//both of these show up, p as above
                              System.out.println(e);
                                        System.out.println(p);
                              p.show(e.getComponent(), e.getX(), e.getY());
                        }
                  }
//called from inner class generated by constructor...

      class PopupListener extends MouseAdapter {
                  extendedPopupMenu pop;
      
                  PopupListener(lpopup p) {
                        pop = p;
              }

              public void mousePressed(MouseEvent e) {
                  maybeShowPopup(e);
              }
              public void mouseReleased(MouseEvent e) {
                  maybeShowPopup(e);
              }
          }      
0
 

Author Comment

by:illucid
ID: 9784855
              PopupListener(lpopup p) {

//is actually ..
               PopupListener(extendedPopupMenu p) {
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 92

Expert Comment

by:objects
ID: 9784860
And where do you create your popup menu?
0
 
LVL 92

Expert Comment

by:objects
ID: 9784864
> p.show(e.getComponent(), e.getX(), e.getY());

where is p defined?
0
 

Author Comment

by:illucid
ID: 9784875
           pop = new extendedPopupMenu();
//from another class. A reference gets passed thru

the constructor where the code above takes pop as a parameter
0
 

Author Comment

by:illucid
ID: 9784899
Heh. Im starting to see why I should be using Class Diagrams
//from within constructor...
            p = pop;   //pop is a reference to the extendedPopupMenu given to the constructor

//where variables are initiated
         extendedPopupMenu p;
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 9784910
>  pop = new extendedPopupMenu();

and what is added to pop?
0
 

Author Comment

by:illucid
ID: 9784917
ublic class extendedPopupMenu extends JPopupMenu {
      
      
      public void showPopup(MouseEvent ev, int x, int y) {
            show(ev.getComponent(), x, y);
      }
      
      public extendedPopupMenu() {
            super();
      }
      
      private void jobs() {
            
      }
      
      private void notes() {
            
      }
      
      private void quotes() {
            
      }      
      
      private void newnote() {
            
      }            
      
      private void newquote() {
            
      }            

      private void excel() {
            
      }            

      private void email() {
            
      }            


      private void makePopup() {
            JMenuItem menuItem;
            menuItem = new JMenuItem("Jobs");
            menuItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                        jobs();
                  }
            });
            add(menuItem);
            menuItem = new JMenuItem("Quotes");
            menuItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                        quotes();
                  }
            });
            add(menuItem);
            menuItem = new JMenuItem("Notes");
            menuItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                        notes();
                  }
            });
            add(menuItem);
            addSeparator();
            menuItem = new JMenuItem("New Quote");
            menuItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                        newquote();
                  }
            });
            add(menuItem);
            menuItem = new JMenuItem("New Note");
            menuItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                        newnote();
                  }
            });
            addSeparator();
            add(menuItem);
            menuItem = new JMenuItem("Excel");
            menuItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                        excel();
                  }
            });
            add(menuItem);
            menuItem = new JMenuItem("Email");
            menuItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                        email();
                  }
            });
            add(menuItem);            
//            menuItem = new JMenuItem("");
//            menuItem.addActionListener(new ActionListener() {
//                  public void actionPerformed(ActionEvent ev) {
//                        #();
//                  }
//            });
//            add(menuItem);
      }            
}
0
 

Author Comment

by:illucid
ID: 9784918
WHOOPS.
0
 

Author Comment

by:illucid
ID: 9784923
Yup, it goes now.

Thanks again!
0
 
LVL 92

Expert Comment

by:objects
ID: 9784960
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question