import javax.swing.JDialog; 
import javax.swing.JFrame; 
import javax.swing.JMenuItem; 
import javax.swing.JPopupMenu; 
import javax.swing.JTextArea; 
import javax.swing.SwingUtilities; 

public class ComponentPopupMenuTest { 
public static void main(String[] args) { 
SwingUtilities.invokeLater(new Runnable() { 
@Override 
public void run() { 
test(); 
} 
}); 
} 

private static void test() { 
JPopupMenu popupMenu = new JPopupMenu(); 
popupMenu.add(new JMenuItem("You should not see me")); 

JFrame frame = new JFrame("Main Frame"); 
frame.getRootPane().setComponentPopupMenu(popupMenu); 
frame.setSize(400, 400); 
frame.setLocation(0, 0); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
frame.setVisible(true); 

JTextArea info = new JTextArea("Do a contextual mouse click here while the Main Frame is active"); 
info.setWrapStyleWord(true); 
info.setLineWrap(true); 

JDialog dialog = new JDialog(frame, "Modeless Dialog", false); 
dialog.getContentPane().add(info); 
dialog.setSize(300, 300); 
dialog.setLocation(50, 50); 
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 
dialog.setVisible(true); 

frame.toFront(); 
} 
} 
