Here you can find the source of setFocus(JComponent component)
public static boolean setFocus(JComponent component)
//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; } }