Re: Set keyboard focus to Applet when it is loaded
- From: "Andrew Thompson" <andrewthommo@xxxxxxxxx>
- Date: 25 Aug 2006 01:29:43 -0700
Felix Natter wrote:
....
I have an applet with a JTextArea and I would like the keyboard focus
to be in that JTextArea as soon as the applet is loaded (so that
the user can immediately start typing).
Use an HTML form <input> element for instantaneous
response, an applet needs to looad the VM, then the applet.
Currently I do two things (with no success):
1. use javascript to set the focus on the <applet> element:
<body onLoad="document.getElementById('kbapplet').focus()">
...
<applet id="kbapplet" code=".."></applet>
This JavaScript is typical of the quality of JS written
by Java programmers. It is horrid.
If you want to pursue the JS strategy (which will
probably be the most successful in this instance)
I suggest you ask the people who know how to do it.
Those people hang out on..
comp.lang.javascript
2. call requestFocus() and textarea.requestFocusInWindow()
in the init() method (as well as in windowOpened-handler etc).
Sun never bothered to specify whether an applet(s) or
other HTML elements should gain the initial focus on
a web-page, so whatever behaviour that a browser
implements, is technically 'correct'.
Some browser/VM combinations give focus to the
applet(s), others don't.
For that basic reason, I think any strategy using Java
completely, is bound to fail. Because calling for focus
*within* an element (the applet) to which the browser
does not give focus (the applet) will most likely fail.
That leaves us with using JS to mediate which
element gets focus.
BTW - the problem is completely solved if you launch
your applet using WebStart. There is no browser/web
page to contend with, and at start-up the first focusable
element within the Applet's focus cycle, will receive
input focus.
Andrew T.
.
- Follow-Ups:
- Re: Set keyboard focus to Applet when it is loaded
- From: Felix Natter
- Re: Set keyboard focus to Applet when it is loaded
- References:
- Set keyboard focus to Applet when it is loaded
- From: Felix Natter
- Set keyboard focus to Applet when it is loaded
- Prev by Date: how to get mouse resolution?
- Next by Date: Re: Set keyboard focus to Applet when it is loaded
- Previous by thread: Set keyboard focus to Applet when it is loaded
- Next by thread: Re: Set keyboard focus to Applet when it is loaded
- Index(es):
Relevant Pages
|