Here you can find the source of requestFocusInWindow(final Component c)
Parameter | Description |
---|---|
c | - the component |
public static void requestFocusInWindow(final Component c)
//package com.java2s; /*//w w w .ja v a 2 s . com * GUIUtils.java * * Copyright (C) 2002-2015 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import java.awt.Component; import java.lang.reflect.InvocationTargetException; import javax.swing.SwingUtilities; public class Main { /** * Executes requestFocusInWindow on the specified component * using invokeLater. * * @param c - the component */ public static void requestFocusInWindow(final Component c) { invokeAndWait(new Runnable() { public void run() { c.requestFocusInWindow(); } }); } /** * Runs the specified runnable in the EDT using * <code>SwingUtilities.invokeAndWait(...)</code>. * Note: This method 'supresses' the method's * thrown exceptions - InvocationTargetException and * InterruptedException. * * @param runnable - the runnable to be executed */ public static void invokeAndWait(Runnable runnable) { if (!SwingUtilities.isEventDispatchThread()) { try { // System.err.println("Not EDT"); SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { } catch (InvocationTargetException e) { } } else { runnable.run(); } } }