• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • 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>
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic