Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane on focusLost  RSS feed

 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • 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,
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi Nathan,
This work now.
Thanks,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!