Thursday, October 7, 2010

How to Initially Set Focus to an Element in Java

Let's say you have a form with a text field, a text area and a button, in that order. You want the user to be able to start typing into the text area right away without having to press the tab key first to go from the top text field to the text area below. Well you need to call the text area's resquestFocus() method. But here is something very important, you have to call that method after you make the form visble by calling setVisible(true). If you do it beforehand, it won't work...

No comments: