Solved

JPopupMenu not showing up

Posted on 2003-11-19
12
380 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 71
Systems talking to each other 5 125
PDFBox - convert image to PDF, PDF resolution 3 117
web services creation SOAP vs REST 5 20
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 covers a step-by-step guide to install VisualVM launcher in eclipse.

920 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

13 Experts available now in Live!

Get 1:1 Help Now