CompoundFocusListener extends AbstractBean { public void release() { removeManagerListener(KeyboardFocusManager.getCurrentKeyboardFocusManager()); removeAllListeners(); this.root = null; } CompoundFocusListener(JComponent root); boolean isFocused(); void release();  }
@Test public void testReleaseRemovesListeners() { CompoundFocusListener l = new CompoundFocusListener(new JXDatePicker()); final PropertyChangeReport report = new PropertyChangeReport(); l.addPropertyChangeListener(report); l.release(); assertRemoved(report, l.getPropertyChangeListeners()); }
@Test public void testRelease() throws InterruptedException, InvocationTargetException { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } JXDatePicker picker = getRealizedDatePicker(); Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); assertFalse("sanity: initial focus must not be in picker", SwingXUtilities.isDescendingFrom(focusOwner, picker)); CompoundFocusListener l = new CompoundFocusListener(picker); final PropertyChangeReport report = new PropertyChangeReport(); l.addPropertyChangeListener(report); l.release(); picker.requestFocusInWindow(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { assertEquals(0, report.getEventCount("focused")); } }); }