[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1713
  • Last Modified:

JTextField

How can the JTextField detect a lost focus. For example,  if a user enter some text into the field and press enter, the field detect the event and we can do some operations when it happens. like..
txtfield.addActionListener(
                          new ActionListener() {
                           public void actionPerformed(ActionEvent e){
                               try {
                                String str = ((JTextField)e.getSource()).getText();
                              int value =Integer.parseInt(str);
                         //some operations with the value...
                               } catch (Exception ee){}
                           }
                          }
                          );
However,  the operation will not be executed if user does not press enter. (e.g click somewhere else).
How can the JTextField do some operations when it looses focus(i.e when user clicks somewhere else)?

Thanx

0
asukai
Asked:
asukai
1 Solution
 
objectsCommented:
txtfield.addFocusListener(...
0
 
yongsingCommented:
txtfield.addFocusListener(
  new FocusAdapter() {
    public void focusLost(FocusEvent focusEvent) {
      if (!focusEvent.isTemporary()) {
        // do some operations
      }
    }
  }
);
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now