How to UnFocus a JTextField

A log-in would be best done in a modal dialog, but that introduces problems in that the method requestFocusInWindow() must be called after the component is visible, but that is blocked by the fact the dialog is modal! This example uses Rob Camick’s RequestFocusListener (as presented in Dialog Focus) to manage focus after the dialog … Read more

EditText, clear focus on touch outside

Building on Ken’s answer, here’s the most modular copy-and-paste solution. No XML needed. Put it in your Activity and it’ll apply to all EditTexts including those within fragments within that activity. @Override public boolean dispatchTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { View v = getCurrentFocus(); if ( v instanceof EditText) { Rect outRect = … Read more

How to detect when a tab is focused or not in Chrome with Javascript?

2015 update: The new HTML5 way with visibility API (taken from Blowsie’s comment): document.addEventListener(‘visibilitychange’, function(){ document.title = document.hidden; // change tab text for demo }) The code the original poster gives (in the question) now works, as of 2011: window.addEventListener(‘focus’, function() { document.title=”focused”; }); window.addEventListener(‘blur’, function() { document.title=”not focused”; }); edit: As of a few … Read more

Mobile Safari: Javascript focus() method on inputfield only works with click?

Actually, guys, there is a way. I struggled mightily to figure this out for [LINK REMOVED] (try it on an iPhone or iPad). Basically, Safari on touchscreen devices is stingy when it comes to focus()ing textboxes. Even some desktop browsers do better if you do click().focus(). But the designers of Safari on touchscreen devices realized … Read more