Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JTextField.requestFocus is not working in jre 1.6

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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