• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField.requestFocus is not working in jre 1.6

 
Barun Das
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an applet which pops a JDialog which has one JTextField, one JPasswordField and two buttons. By default JTextField should have the focus and for that I code like this:

SwingUtilities.invokeLater(new FocusRequestor(comp));

class FocusRequestor extends Thread
{
private Component component;
FocusRequestor(Component c) {
component = c;
}
public void run() {
if (component.getParent() != null) {
component.requestFocusInWindow();
}
}
}

Now the problem is its working fine with jre 1.5 but with jre 1.6, I am not getting the focus all time. If I ALT+TAB to another window and then come back to my dialog then I am getting the focus.

Can anyone help me? Is this a problem with java 1.6.

I am using jre1.6.0_07 and IE7 when its working fine with jre 1.5.0_09.

Thanks in advance.

Barun.
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was having the same issue (JDialog in applet) until I added this to the constructor of the dialog:

<blockquote>code:
<pre name="code" class="core">
addWindowListener(new WindowAdapter()
{
public void windowOpened(WindowEvent e)
{
inputField.requestFocus();
}
}
</pre>
</blockquote>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!