Forum Discussion

Cizo89's avatar
Cizo89
Frequent Contributor
12 years ago

Problem with custom JPopupMenu

Hi,

I would like to create a Popup Menu in SoapUI, using the method showPopup in class UISupport.

I have my compiled jar in ext folder, correctly created actions xml file in actions folder, but while trying to invoke it in SoapUI I'm receiving this error message:

Wed Sep 25 15:51:42 BST 2013:ERROR:java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
at java.awt.Component.getLocationOnScreen_NoTreeLock(Unknown Source)
at java.awt.Component.getLocationOnScreen(Unknown Source)
at com.eviware.soapui.support.UISupport.showPopup(UISupport.java:570)
at com.eviware.soapui.support.UISupport$showPopup.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at Framework.SyncAction.perform(SyncAction.groovy:28)
at com.eviware.soapui.support.action.swing.SwingActionDelegate.actionPerformed(SwingActionDelegate.java:89)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Here is my code:

package Framework

import com.eviware.soapui.model.ModelItem;
import com.eviware.soapui.support.UISupport
import com.eviware.soapui.support.action.support.AbstractSoapUIAction

import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.border.BevelBorder;
import java.awt.Point

class SyncAction extends AbstractSoapUIAction{

public SyncAction(){
super( "Synchronize project", "Sync the project with actual resources, scripts and DataSources" )
}

public void perform( ModelItem target, Object param ){
JPopupMenu popup = new JPopupMenu("Test Popup Menu")

JMenuItem item = new JMenuItem("TestItem")
item.setHorizontalTextPosition(JMenuItem.RIGHT)

popup.add(item)
popup.setBorder(new BevelBorder(BevelBorder.RAISED))

UISupport.showPopup(popup, UISupport.createEmptyPanel(100, 100, 100, 100), new Point())
}
}


Thanks for help

Regards,
Marek
  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi,

    yes, I've already seen that page, in fact that's what I did - I've my own action, which is appearing at the end of the my composition project popup.
    After clicking on the action in that example, an Information window is displayed.

    In my action I want to display a new Popup menu after clicking on it.
    I know how to display confirmation window, info window, error window and etc, but the only problem is that I don't know how to display new Popup Menu.
    I'm still getting that error message mentioned above.

    Thanks for any help

    Regards,
    Marek
  • Hmm ... Unfortunately the code you provide kind of breaks the contract of the showPopup() method. You are supposed to pass the parent Component (the one on which the popup is to be displayed) as the second param. In my understanding you're getting the error because the dummy panel isn't displayed. So what you'd really want is to pass the popup menu item itself, but as far as I know you can't get it via this API.

    However, I'll discuss it with some other developers and see if there's a way to do it. If not you'll have to use a little window rather than a submenu, for the time being.

    Regards,
    Manne