public static void setAutoRequestFocus(JFrame window, boolean autoRequestFocus) { try { Method setAutoRequestFocusMethod = window.getClass().getMethod("setAutoRequestFocus", boolean.class); setAutoRequestFocusMethod.invoke(window, autoRequestFocus); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (SecurityException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }