Solved

JPopupMenu not showing up

Posted on 2003-11-19
12
392 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
windows explorer path to command prompt 5 54
eclipse apache tomcat admin console 52 122
difference between sorce folder and folder in eclipise 3 29
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

828 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