Can not add JPopupMenu to contentPane

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Can not add JPopupMenu to contentPane

Postby mkornatzki » Fri Jun 25, 2010 12:23 am

Hi,

if i try to set a JPopoupMenu to a Panel with GridBagLayout the SwingDesigner react with a "WindowBuilder internal error".
Code: Select all
java.lang.NullPointerException
   at com.instantiations.designer.swing.model.layout.gbl.GridBagConstraintsInfo.getCurrentObjectFields(GridBagConstraintsInfo.java:55)
   at com.instantiations.designer.swing.model.layout.gbl.AbstractGridBagConstraintsInfo.refresh_fetch(AbstractGridBagConstraintsInfo.java:122)
   at com.instantiations.designer.core.model.ObjectInfo.refresh_fetch(ObjectInfo.java:566)
   at com.instantiations.designer.swing.model.component.ComponentInfo.refresh_fetch(ComponentInfo.java:139)
   at com.instantiations.designer.swing.model.component.ContainerInfo.refresh_fetch(ContainerInfo.java:227)
   at com.instantiations.designer.swing.model.component.menu.JPopupMenu_Info.refresh_fetch(JPopupMenu_Info.java:96)
   at com.instantiations.designer.core.model.ObjectInfo.refresh_fetch(ObjectInfo.java:566)
   at com.instantiations.designer.swing.model.component.ComponentInfo.refresh_fetch(ComponentInfo.java:139)
   at com.instantiations.designer.swing.model.component.ContainerInfo.refresh_fetch(ContainerInfo.java:227)
   at com.instantiations.designer.core.model.ObjectInfo.refresh_fetch(ObjectInfo.java:566)
   at com.instantiations.designer.swing.model.component.ComponentInfo.refresh_fetch(ComponentInfo.java:139)
   at com.instantiations.designer.swing.model.component.ContainerInfo.refresh_fetch(ContainerInfo.java:227)
   at com.instantiations.designer.core.model.ObjectInfo$5$1.run(ObjectInfo.java:439)
   at com.instantiations.designer.core.utils.execution.ExecutionUtils.runDesignTime(ExecutionUtils.java:122)
   at com.instantiations.designer.core.model.ObjectInfo$5.run(ObjectInfo.java:436)
   at com.instantiations.designer.swing.utils.SwingUtils$1.run(SwingUtils.java:60)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


The problem is that the generated source looks like
Code: Select all
GridBagConstraints gbc_extPopupMenu = new GridBagConstraints();
...
contentPane.add(getExtPopupMenu(), gbc_extPopupMenu);


But it should be something like this
Code: Select all
   addPopup(getPanel(), getExtPopupMenu());

   protected ExtPopupMenu getExtPopupMenu() {
      if (extPopupMenu == null) {
         extPopupMenu = new ExtPopupMenu();
      }
      return extPopupMenu;
   }
   private static void addPopup(Component component, final JPopupMenu popup) {
      component.addMouseListener(new MouseAdapter() {
         public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
               showMenu(e);
            }
         }
         public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
               showMenu(e);
            }
         }
         private void showMenu(MouseEvent e) {
            popup.show(e.getComponent(), e.getX(), e.getY());
         }
      });
   }

or maybe not allow to put a PopupMenu on a Container.

regards,
michael
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: Can not add JPopupMenu to contentPane

Postby Eric Clayberg » Sat Jun 26, 2010 5:27 am

Give this a try using the latest Swing Designer v7.6 build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Can not add JPopupMenu to contentPane

Postby mkornatzki » Sun Jun 27, 2010 10:21 pm

thanks, it works.

cheers, michael
mkornatzki
 
Posts: 121
Joined: Wed Oct 15, 2008 3:57 am

Re: Can not add JPopupMenu to contentPane

Postby Eric Clayberg » Mon Jun 28, 2010 8:02 am

Glad that worked for you.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest