Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
  protected void installKeyboardActions(final JRootPane root) {
    SwingUtilities.replaceUIActionMap(root, getActionMap(root));

    Utilities.installKeyboardActions(
        root,
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
        "RootPane.ancestorInputMap",
        "RootPane.ancestorInputMap.RightToLeft");
    if (root.getDefaultButton() != null) {
      loadDefaultButtonKeyBindings(root);
    }
  }
 @Override
 @Nullable
 public JComponent getPreferredFocusedComponent() {
   final JRootPane pane = getRootPane();
   return pane != null ? pane.getDefaultButton() : null;
 }
 public void actionPerformed(final ActionEvent e) {
   if (isEnabled() && press) {
     root.getDefaultButton().doClick(25);
   }
 }
 public boolean isEnabled() {
   JButton defaultButton = root.getDefaultButton();
   return (defaultButton == null) ? false : defaultButton.isEnabled();
 }