Solved

JPopupMenu not showing up

Posted on 2003-11-19
12
374 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
Comment Utility
> My problem is the menu wont show up.

post the code that pops it up.
0
 

Author Comment

by:illucid
Comment Utility

                  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
Comment Utility
              PopupListener(lpopup p) {

//is actually ..
               PopupListener(extendedPopupMenu p) {
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
And where do you create your popup menu?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> p.show(e.getComponent(), e.getX(), e.getY());

where is p defined?
0
 

Author Comment

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

the constructor where the code above takes pop as a parameter
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:illucid
Comment Utility
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
Comment Utility
>  pop = new extendedPopupMenu();

and what is added to pop?
0
 

Author Comment

by:illucid
Comment Utility
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
Comment Utility
WHOOPS.
0
 

Author Comment

by:illucid
Comment Utility
Yup, it goes now.

Thanks again!
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now