• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JOptionPane on focusLost

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I need show a message with JOptionPane on focusLost event of a component.
Because this code "freeze".
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
public class Test extends JFrame implements FocusListener{
JTextField field1;
JTextField field2;
public static void main(String[] args){
Test t = new Test();
t.init();
}
public Test(){
field1 = new JTextField("");
field2 = new JTextField("");
}
public void init(){
field1.addFocusListener(this);
field2.addFocusListener(this);
getContentPane().add(field1, BorderLayout.NORTH);
getContentPane().add(field2, BorderLayout.SOUTH);
setSize(200,200);
setVisible(true);
}
public void focusGained(FocusEvent e){
}
public void focusLost(FocusEvent e){
JOptionPane.showMessageDialog(null, "Lost Focus ");
}
}
-----
Have i call JOptionPane.showMessageDialog on a Thread?
Best Regards,
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes... looks like the new Focus API has introduced some problems, maybe? I found a posting complaining about this same problem on Sun's java forums, but couldn't find anything yet about it in the bug database... it should work fine if you replace it with :


(I added the temporary check so the dialog only gets launched once...)
[ January 07, 2003: Message edited by: Nathan Pruett ]
 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nathan,
This work now.
Thanks,
reply
    Bookmark Topic Watch Topic
  • New Topic