If you want to share an Object then you need to create the Object and pass the Object as a parameter to your other classes. Something like:
JPopupMenu popup = createSharedPopupMenu();
Pane.addTab("TabOne", M.new DebugBox(500, 500, popup));
Pane.addTab("TabTwo", M.new DebugBox(500, 500, popup));
Then you need to create generic Actions that will work on any text component. The DefaultEditorKit provides some of these Actions for you:
public JPopupMenu createSharedPopupMenu()
{
JPopupMenu popup = new JPopupMenu()
JMenuItem copy = new JMenuItem( new DefaultEditorKit.CopyAction() );
popup.add( copy );
...
return popup.
}
If the editor kit doesn't provide an Action for you then you need to create your own and you should extend TextAction
instead of AbstractAction. The TextAction class has a method that will return the text component that has focus. So you can implement the Action in a generic way.
Also you don't need to use a MouseListener to invoke the popup. You can just use the following JComponent method:
JComponent.setComponentPopupMenu(JPopupMenu popup)