Java Swing Focus setFocus(JComponent component)

Here you can find the source of setFocus(JComponent component)

Description

set Focus

License

Open Source License

Declaration

public static boolean setFocus(JComponent component) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.JComponent;

import javax.swing.JSpinner;

import javax.swing.text.JTextComponent;

public class Main {
    public static boolean setFocus(JComponent component) {
        if (component.requestFocusInWindow()) {
            if (component instanceof JSpinner)
                component = ((JSpinner) component).getEditor();
            if (component instanceof JTextComponent) {
                JTextComponent textComponent = (JTextComponent) component;
                textComponent.setCaretPosition(textComponent.getDocument().getLength());
            }/*from  w ww  .j av a2  s.  c o  m*/
            return true;
        }
        return false;
    }
}

Related

  1. requestFocus(final JComponent component)
  2. requestFocus(final Window win, final Component comp)
  3. requestFocusInWindow(final Component c)
  4. selectAllOnFocusGained()
  5. selectAndFocus(JComponent component)
  6. setFocusableRecursively(final JComponent component, final boolean focusable, final boolean childsOnly)
  7. setFocusOn(Component component)
  8. setFocusOrder(JComponent... components)
  9. setNextFocusable(JComponent component, final JComponent nextFocusable)