Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JPopupMenu not showing up

Posted on 2003-11-19
12
Medium Priority
?
415 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

773 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