示例#1
0
  /*
   * Fix for BugTraq ID 4041703.
   * Set the focus to a reasonable default for an Applet.
   */
  private void setDefaultFocus() {
    Component toFocus = null;
    Container parent = getParent();

    if (parent != null) {
      if (parent instanceof Window) {
        toFocus = getMostRecentFocusOwnerForWindow((Window) parent);
        if (toFocus == parent || toFocus == null) {
          toFocus = parent.getFocusTraversalPolicy().getInitialComponent((Window) parent);
        }
      } else if (parent.isFocusCycleRoot()) {
        toFocus = parent.getFocusTraversalPolicy().getDefaultComponent(parent);
      }
    }

    if (toFocus != null) {
      if (parent instanceof EmbeddedFrame) {
        ((EmbeddedFrame) parent).synthesizeWindowActivation(true);
      }
      // EmbeddedFrame might have focus before the applet was added.
      // Thus after its activation the most recent focus owner will be
      // restored. We need the applet's initial focusabled component to
      // be focused here.
      toFocus.requestFocusInWindow();
    }
  }
示例#2
0
 @Override
 public boolean editCellAt(final int row, final int column, final EventObject event) {
   final boolean editingStarted = super.editCellAt(row, column, event);
   if (editingStarted) {
     final CellEditor cellEditor = getCellEditor();
     try {
       final Object o = cellEditor.getClass().getMethod("getComponent").invoke(cellEditor);
       if (o instanceof Component) {
         ((Component) o).requestFocusInWindow();
       }
     } catch (final Exception e) {
       // ignore
     }
   }
   return editingStarted;
 }
  /*
   *	Tab has changed. Focus on saved component for the given tab.
   *  When there is no saved component, focus on the first component.
   */
  public void stateChanged(ChangeEvent e) {
    Component key = tabbedPane.getComponentAt(tabbedPane.getSelectedIndex());

    if (key == null) return;

    Component value = tabFocus.get(key);

    //  First time selecting this tab or focus policy is RESET_FOCUS

    if (value == null) {
      key.transferFocus();
      tabFocus.put(key, value);
    } else //  Use the saved component for focusing
    {
      value.requestFocusInWindow();
    }
  }
示例#4
0
  public void setVisible(boolean b) {
    KeyboardFocusManager keyboardFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (b) {
      keyboardFocusManager.addKeyEventDispatcher(keyManager);
    } else {
      keyboardFocusManager.removeKeyEventDispatcher(keyManager);
    }
    super.setVisible(b);

    Window owner = getOwner();
    if (owner != null) {
      owner.requestFocus();
      if (lastFocusOwner != null) {
        lastFocusOwner.requestFocusInWindow();
      }
    }
  }
 /**
  * Requests focus unless the component already has focus. For some weird reason calling {@link
  * Component#requestFocusInWindow()}when the component is focus owner changes focus owner to
  * another component!
  *
  * @param component the component to request focus for
  * @return true if the component has focus or probably will get focus, otherwise false
  */
 public static boolean requestFocus(Component component) {
   return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == component
       || component.requestFocusInWindow();
 }
示例#6
0
 /**
  * Sets the help text for the specified component.
  *
  * @param cont input container
  */
 static void focus(final Component cont) {
   final GUI gui = gui(cont);
   if (gui == null) return;
   if (gui.gopts.get(GUIOptions.MOUSEFOCUS) && cont.isEnabled()) cont.requestFocusInWindow();
 }