CompoundFocusListener extends AbstractBean { public boolean isFocused() { return focused; } CompoundFocusListener(JComponent root); boolean isFocused(); void release();  }
@Test public void testFocusedInitialFalse() { JComboBox field = new JComboBox(); field.setEditable(true); assertFalse("sanity: combo not focused", field.hasFocus()); CompoundFocusListener l = new CompoundFocusListener(field); assertEquals(field.hasFocus(), l.isFocused()); }
@Test public void testFocusedInitialTrue() throws InterruptedException, InvocationTargetException { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } final JXDatePicker picker = getRealizedDatePicker(); picker.requestFocusInWindow(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); assertTrue("sanity: focus transfered into picker hierarchy", SwingXUtilities.isDescendingFrom(focusOwner, picker)); CompoundFocusListener l = new CompoundFocusListener(picker); assertTrue("listener must take initial focused state ", l.isFocused()); } }); }