public static JFrame getOwner(ActionEvent e)
{
Object source = e.getSource();
JFrame frame = null;
while(source instanceof MenuElement)
{
source = ((MenuElement)source).getComponent();
if(source instanceof JPopupMenu)
source = ((JPopupMenu)source).getInvoker();
else
source = ((Component)source).getParent();
}
if(source instanceof Component)
{
Component parent = SwingUtilities.getRoot((Component)source);
if(parent instanceof JFrame)
frame = (JFrame)parent;
}
if(frame == null)
{
for(Object obj : JFrame.getFrames())
{
if(obj instanceof JFrame)
{
frame = (JFrame)obj;
break;
}
}
}
return frame;
}