Java Code Examples for javax.swing.JRootPane#setDefaultButton()

The following examples show how to use javax.swing.JRootPane#setDefaultButton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyledButtonUI.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Change the default button of the root pane of the specified
 * component.
 *
 * @param component the component whose root pane's default button
 *	should be changed. It must be a JButton.
 * @param setDefault if <code>true</code>, set the JButton specified by
 * 	<code>component</code> as the default. Otherwise the default button
 * 	is set to none
 */
private void changeDefault(Component component, boolean setDefault) {
	if (component instanceof JButton) {
		JButton button = (JButton) component;
		JRootPane parent = button.getRootPane();
		/*
		 * In some conditions, when pushing the button results
		 * in it being removed from the root container, a focus
		 * event can be processed after the button (or its parents)
		 * has been removed, so we need to check for a non-null
		 * root for a focused button, even though that seems
		 * nonsensical.
		 */
		if (parent != null) {
			if (setDefault) {
				parent.setDefaultButton(button);
			} else {
				parent.setDefaultButton(null);
			}
		}
	}
}
 
Example 2
Source File: FreeColOptionPaneUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void selectInitialValue(JOptionPane op) {
    if (initialFocusComponent != null) {
        initialFocusComponent.requestFocus();
 
        if (initialFocusComponent instanceof JButton) {
            JRootPane root = SwingUtilities.getRootPane(initialFocusComponent);
            if (root != null) {
                root.setDefaultButton((JButton)initialFocusComponent);
            }
        }
    }
}
 
Example 3
Source File: DefaultRegistry.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
public DefaultRegistry(JRootPane rootPane) {
	this.rootPane = rootPane;
	rootPane.setDefaultButton(null);
}