• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

JTextField.requestFocus is not working in jre 1.6

 
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.
 
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>
 
reply
    Bookmark Topic Watch Topic
  • New Topic