Window window = SwingUtilities.getWindowAncestor(rootPane); window.addWindowFocusListener(new WindowFocusListener() { public void windowGainedFocus(WindowEvent ev) { repaint(); } public void windowLostFocus(WindowEvent ev) { repaint(); } });
MouseInputAdapter mouseHandler = new MouseHandler(); addMouseListener(mouseHandler); addMouseMotionListener(mouseHandler);
    private void installListeners()    {      Window window = SwingUtilities.getWindowAncestor(rootPane);      window.addWindowFocusListener(new WindowFocusListener()                       {                         public void windowGainedFocus(WindowEvent ev)                         {                           repaint();                         }                         public void windowLostFocus(WindowEvent ev)                         {                           repaint();                         }                       });    }