/** * Overrides <code>JComponent.removeNotify</code> to check if this button is currently set as the * default button on the <code>RootPane</code>, and if so, sets the <code>RootPane</code>'s * default button to <code>null</code> to ensure the <code>RootPane</code> doesn't hold onto an * invalid button reference. */ public void removeNotify() { JRootPane root = SwingUtilities.getRootPane(this); if (root != null && root.getDefaultButton() == this) { root.setDefaultButton(null); } super.removeNotify(); }
/** * Gets the value of the <code>defaultButton</code> property, which if <code>true</code> means * that this button is the current default button for its <code>JRootPane</code>. Most look and * feels render the default button differently, and may potentially provide bindings to access the * default button. * * @return the value of the <code>defaultButton</code> property * @see JRootPane#setDefaultButton * @see #isDefaultCapable * @beaninfo description: Whether or not this button is the default button */ public boolean isDefaultButton() { JRootPane root = SwingUtilities.getRootPane(this); if (root != null) { return root.getDefaultButton() == this; } return false; }