Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2006

Tip: Looking for answers? Try searching our database.

why is focus lost not called

Thread view: 
Timasmith - 01 Nov 2006 03:58 GMT
I have code that executes when focus leaves a text control.
Specifically I grab the text in the control at that time.

   jTextField.addFocusListener(new FocusListener(){
     public void focusGained(FocusEvent e) {
     }
     public void focusLost(FocusEvent e) {
         // calls getText() and does something with it
      }
   });

However if I edit a text field and click on a button, swing does not
execute the focusLost - or if it does it is not with the new value.

It almost seems like a button lets me sneak out of the text control.
Andrew Thompson - 01 Nov 2006 04:16 GMT
...
> It almost seems like a button lets me sneak out of the text control.

<sscce>
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class Focus {
 public static void main(String[] args) {
  JTextField jTextField = new JTextField(20);
  jTextField.addFocusListener(new FocusListener(){
       public void focusGained(FocusEvent e) {
       }
       public void focusLost(FocusEvent e) {
           // calls getText() and does something with it
           System.out.println(e);
           // ...almost seems you are not doing anything!
        }
     });
  JTextField jTextField2 = new JTextField(20);
  JPanel p = new JPanel();
  p.add(jTextField);
  p.add(jTextField2);
  JOptionPane.showMessageDialog(null,p);
 }
}
</sscce>

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.