?
Solved

JTextField

Posted on 2003-03-11
2
Medium Priority
?
1,712 Views
Last Modified: 2006-11-17
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
Comment
Question by:asukai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8109596
txtfield.addFocusListener(...
0
 
LVL 9

Accepted Solution

by:
yongsing earned 200 total points
ID: 8109816
txtfield.addFocusListener(
  new FocusAdapter() {
    public void focusLost(FocusEvent focusEvent) {
      if (!focusEvent.isTemporary()) {
        // do some operations
      }
    }
  }
);
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question