JTextFields sometimes still contains old values even setText("") performed

I have a program which let user enter 3 JTextFields : hostname, userid, password, and one JButton. When the button is clicked, below function will be executed to get the value of the JTextField, then relevant function will be called.
My problem is when I run the program, sometimes it will get the "previous" value, sometimes it works correctly. I make sure all JTextFields values will be cleared each time, but no help. Here is part of my code:
    private void sendActionPerformed(java.awt.event.ActionEvent evt) {                                    
        String hn = hostname.getText();
        String ln = login.getText();
        String pd = password.getText();
        hostname.setText("");
        login.setText("");
        password.setText("");
        result.setText("");
        p  = new Process();
        p.setPara(hn,ln,pd);
        result.setText(p.sendmail());
        p = null;      
    }Does anyone have ideas or suggestion? Thx.

Ok, there are 2 files, the main class is the Email.java file.
Email.java
public class Email extends javax.swing.JFrame {
    /** Creates new form Email */
    public Email() {
        initComponents();
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        hostname = new javax.swing.JTextField();
        login = new javax.swing.JTextField();
        password = new javax.swing.JTextField();
        send = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        result = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("HostName (blank for localhost):");
        jLabel2.setText("Login:");
        jLabel3.setText("Password:");
        hostname.setText("smtp.test.com");
        login.setText("[email protected]");
        login.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginActionPerformed(evt);
        password.setText("mypassword");
        send.setText("Send");
        send.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendActionPerformed(evt);
        result.setColumns(20);
        result.setEditable(false);
        result.setLineWrap(true);
        result.setRows(5);
        jScrollPane1.setViewportView(result);
        jLabel4.setText("Result:");
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(hostname, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(login, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(161, 161, 161)
                        .addComponent(send))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)))
                .addGap(123, 123, 123))
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(hostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(login, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(send))
                .addGap(20, 20, 20)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(110, 110, 110))
        pack();
    }// </editor-fold>
    private void sendActionPerformed(java.awt.event.ActionEvent evt) {                                    
        String hn = hostname.getText();
        String ln = login.getText();
        String pd = password.getText();
        //result.setText("hn:"+hn+",ln:"+ln+"pd:"+pd);
        hostname.setText("");
        login.setText("");
        password.setText("");
        result.setText("");
        p  = new Process();
        p.setPara(hn,ln,pd);
        result.setText(p.sendmail());
        p = null;
     * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Email().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JTextField hostname;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField login;
    private javax.swing.JTextField password;
    private javax.swing.JTextArea result;
    private javax.swing.JButton send;
    // End of variables declaration
    private Process p;
Process.java
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import java.util.Random;
public class Process {
private Boolean shouldAuth = false;
private String SMTP_HOST_NAME = "";
private String SMTP_AUTH_USER = "";
private String SMTP_AUTH_PWD  = "";
private String emailMsgTxt;
private String emailSubjectTxt;
private String emailFromAddress;
private Boolean isError = false;
private String output = "";
private Random ran;
  public Process(){}
  public void setPara(String hostname, String username, String password){
      if((hostname.equalsIgnoreCase(""))||(hostname == null)){
        SMTP_HOST_NAME = "localhost";
            shouldAuth = false;
      }else{
          shouldAuth = true;
          SMTP_HOST_NAME = (hostname == "") ? "" : hostname;
          SMTP_AUTH_USER = (username == "") ? "" : username;
          SMTP_AUTH_PWD = (password == "") ? "" : password;
      emailFromAddress = "[email protected]";
      emailSubjectTxt = "testing email from abchk";
      emailMsgTxt = "This is a testing message to test the JavaMail."; 
  private class SMTPAuthenticator extends javax.mail.Authenticator{
      public PasswordAuthentication getPasswordAuthentication()
          String username = SMTP_AUTH_USER;
          String password = SMTP_AUTH_PWD;
          return new PasswordAuthentication(username, password);
  public String debug(){
      String tmp = "Output is: ";
      ran = new Random();
      Integer no = ran.nextInt(100);
      return tmp + no.toString();        
  public String sendmail(){
    //Set the host smtp address
    Properties props = new Properties();
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", (shouldAuth==true)? "true":"false");
    Session sess;
    if(shouldAuth==true){
        Authenticator auth = new SMTPAuthenticator();
        sess = Session.getDefaultInstance(props, auth);
        //System.out.println("true");
    }else{
        sess = Session.getInstance(props);
        //sess = Session.getDefaultInstance(props, null);
        //System.out.println("false");
    sess.setDebug(false);
    //Create a message
    Message msg = new MimeMessage(sess);
    //Set message
    String tmp = "";
    try{
      msg.setFrom(new InternetAddress(emailFromAddress));
      msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]"));
      msg.setSubject(emailSubjectTxt);
      msg.setText(emailMsgTxt);
      Transport.send(msg);
    }catch(SendFailedException sfe){
      tmp += "SendFailedException:"+sfe.toString()+"\r\n";
    }catch(AddressException ae){
      tmp += "AddressException:" +ae.toString()+"\r\n";
    }catch(MessagingException me){
      tmp += "MessagingException:" +me.toString()+"\r\n";
    }catch(Exception e){  
      tmp += "Exception:" + e.toString()+"\r\n";       
    if(tmp.equalsIgnoreCase("")){
      tmp += "Email will be successfully delivered IF(*) information is correct.";
    String more = debug();
    return tmp + "\r\n" + more;
}the problem was described as the 1st post, after pressing the send button, the later output message MAY NOT reflect the result, that means even try catch catches the error, the output message still MAY display the previous message, which will misleads the user.

Similar Messages

  • List ItemRenderer contains old values

    Hi Everyone,
         I have used List for show the data from db. Data will update periodically. My problem is some rows contains old values. I have tried validateNow(), invalidateList...
    But I cant achieve the result.
    Kindly Suggest me the possible ways to reset the Data.
    Thanks in Advance.
    Arun P. Ganesh

    If you are using custom ItemRenderer, you need to declare a variable within custom ItemRenderer and use that variable to display the data.

  • OAM- http header containing old value

    Hi,
    I am using OAM to protect one web application and need to pass few http headers to the application for funtioning.
    Issue is one of my http header takes older value only even after its value is changed in repository. Due to this user is stuck in that loop only for some time and after 15-20 mins it gets updated in http header.
    Please let me know what could be the reson for this. Is this caching issue? if yes where excatly can this be updated.
    Thanks
    Sandy

    Hi Sandy,
    Yes, it sounds like a caching issue. If the user has an existing OAM session when the attribute is changed, the attribute is stored in the Access Server cache. You can lower the cache (Access Server settings) but this couls have a detrimental effect on perfomance. If you are updated the attributes from the WebPass, then you can enable automatic cahce flushing for this purpose. (Answer assume OAM 10g, by the way.)
    Regards,
    Colin

  • Function Module Changed - Selection Screen still has old values

    Hi All,
    Our data source uses a function module while extraction. (generic)
    We have changed the Text Symbols in our function module.
    In the function module we fill one particular field (master data) as per the logic.
    The changes done are reflected in the dataloads and data is fine in BW.
    our problem is the selection screen in BW and in the reports, it shows the older values as well for that particular field.
    Can anyone help us in this regard?
    thanks
    Sudeepti

    Sudeepti,
    run program
    rsdds_aggregates_maintain for the relevant infoobjects and see if the change is carried over..
    Also check if the text tables for the same refer to the older values...
    Arun
    Assign points if useful

  • How to change the dynamically  LOV value to old value if it errors out

    We have an use case like when a value is selected from LOV, some validations(EO validations) occur on that and if the validation fails we are throwing exception.But the new value is appearing in LOV text box. We need to display the old value in the LOV if the validation fails. Can you please let me know if there is any way to do that?

    After thinking about this, I wondered if I had mis-read the use-case....so I added #2
    Please state your Jdeveloper version, and elaborate on your use-case:
    *1. Are you saying that the LOV contains incorrect values that the user has chosen?*
    If so you should restrict the LOV values to what is acceptable for the row (based on what other values are in the row)
    By restricting the values in the LOV the wrong value can no longer be selected, you would not need to build in functionality to revert back to previous values.
    I woud start by creating a view criteria for the view object the LOV is based on. The form values would send the binding variables to the view criteria, and that would then execute the query (invoking the view criteriea). The LOV would then contain some information on only acceptable values.
    You may be able to adapt some of the ideas presented in this video (on cascading list boxes) to make your LOV work properly. http://youtu.be/WTevRnXq04o
    This video shows some ways to manipulate view criteria: http://youtu.be/dX93fiBCxEg
    *2. Are you saying that the user has selected other fields in the form -- validation on those fields fails, and you want to revert back, but the LOV still contains the values selected?*
    In that case, you need to clear the values in the form and re-execute the view object -- and refreshing to the correct value.
    Stuart
    Edited by: Stuart Fleming on Sep 12, 2012 12:04 PM
    Edited by: Stuart Fleming on Sep 12, 2012 6:52 PM
    Edited by: Stuart Fleming on Sep 12, 2012 6:52 PM

  • Why substitution strings are keeping old value in translated application even after seed/publish?

    Hi,
    Recently I have notice a small but from the point of view of our customer "big" issue. We have defined in our application some substitution strings to keep more detailed information about the version of the application. They are later used in page templates to show mentioned info to the end users. Recently I had to update value of one of the substitution strings. The change is immediately visible in main application. Unfortunately it is not the case for the translated application. For some reason old value is kept. Even after doing "Seed" -> "Apply translation file" -> "Publish". It is still preserving the old value. I have tried to use "Translatable" checkbox in the template. In the translation file it is showing properly substitution string in the "source" and "target" tags but still it is resolved to the old value.
    We are using APEX 4.2.2.00.11 running on 11g.
    Waiting for any suggestions as maybe it is me forgetting about ticking somewhere additional "checkbox". Thank you in advance.
    Greetings,
    kempiak

    It was my mistake. Value of the substitution string is included in the translation file. I have changed it there and it works perfectly.
    Greetings,
    kempiak

  • How do I sync my iPhone 5 to my new PC? iTunes will not recognize it even when plugged in the USB port. Settings General iTunes wifi sync is still my old laptop. Any help is appreciated.

    How do I sync my iPhone 5 to my new PC? iTunes will not recognize it even when plugged in the USB port. Settings>General>iTunes wifi sync is still my old laptop. Any help is appreciated.

    See also Recover your iTunes library from your iPod or iOS device.
    tt2

  • I recently changed my internet service provider and my e mail address. I updated my iTunes account with the new e mail. Now I cannot get updates on my devices, because the login box on each still contains my old e mail. How can I change this please?

    I recently changed my internet service provider and my e mail address. I updated my iTunes account with the new e mail. Now I cannot get updates on my devices, because the login box on each device still contains my old e mail, and I do not know how to change this How can I change this please?

    Try tapping on the id in Settings > iTunes & App Stores on your devices (Settings > Store if they aren't on iOS 6+) and then log back in and see if that 'refreshes' the account on them.

  • When i updated my username on laptop, my i touch still showing "old" user name even after sync.

    When i updated my userid at apple web site using my laptop, my i touch still showing "old" userid and will not accept "old" or new password even after sync.

    What do you mean you "had to unlock it"?  Do you mean you jailbroke it?  If it was jailbroken and you updated iOS, then wiping it out is the natural consequence of that.

  • Just activated iphone 4S and can't get new voicemail greeting to take.  Old greeting still plays from old phone and that phone still receives voicemail nofications even though it is no longer active.  What is going on?

    Just activated iphone 4S and can't get new voicemail greeting to override the old greeting.  Greeting from previous phone still plays even though a new greeting has been saved to the iphone.  Also, the previous phone still receives voicemail nofications even though it is no longer active.  What is going on?

        We want to make sure that voicemail transition is super smooth SonyBony! Please be aware you must power off the previous device in order for the complete switchover to take place. We recommend leaving the previous device off now that you have activated your new device. Here is a link for additional assistance with voicemail on the iPhone 4s. http://vz.to/1kcyBlo
    JonathanK_VZW
    VZWSupport
    Follow Us on Twitter@VZWSupport

  • If I change the Album Name, the Album Column still sorts by the old name even the new name is listed.

    If I change the Album Name, the Album Colum still sorts the song by the old name even though it shows the new changed name.
    This happens for a song I bought from the iTunes Store. When I change the Album Name on songs read in from CDs, it sorts by
    the Album Name which I edit.

    Changing file or folder names by hand makes iTunes loose contact with the files. You shouldn't do this. If the files are stored inside the iTunes Media folder and you have the option "Keep iTunes Media folder organized" enabled then files with move around as you edit their tags. If they are stored elsewhere, or that option isn't selected, then if you want to rename the files you need to remove and then reimport, or manually reconnect each track one by one.
    Select all of the tracks of the album, press Ctrl+I to Get Info, select the Sorting tab, delete the contents of any of the Sort fields, click OK. This should resolve the sorting issue.
    tt2

  • Searching Web Apps with Data Source fields containing multiple values

    I have a Web App with a field allowing multiple values to be entered similar to the checkbox list. I need to restrict allowed values to a large, finite list of values currently stored in another Web App as the data source. I can't apply the Data Source field type as that only allows single value selection. I also need to be able to use the Web App Search form to search for items containing 1 OR more values in this field (the search functionality of a checklist field type). Here's what I've tried for field types:
    Text (string) or Text (multiline) field type - By saving a list of comma separated values (the same way that checkbox list outputs) to a text input or textarea, the search logic only searches for exact string (including commas) and doesn't parse the individual values.
    List (checkbox list) field type - This allows me to search multiple values using OR logic, but the web app will only store values that have been entered as options in the actual web app field setup. I tried using a checkbox list with minimal or empty options hoping that whatever values I sent over in a comma separated string value would still get stored, but because the values came from my Web App data source and not the list of options stored with the field, they were not saved.
    Has anyone found a way to do this?
    My other question is about how I might use a similar multi-value field as described above but return search results containing items with ALL selected values for that field (AND logic).
    Can anyone enlighten me to the inner workings of BC web app search logic?

    Thanks Robert.
    You'll need to create your own interface to the webapp database for those kind of data operations
    by this, are you speaking of the internal BC database which stores web app schema data? That would be great if it were possible to update that programmatically because I need to use the List (Checkbox List) field type (for the search functionality), but I need to supply the checkbox options from a web app rather than by manually updating the list entered in the Fields view of the web app settings (shown below).
    I'm curious if anyone else has tried this?
    Again, my reason for needing to use the List (Checkbox List) field type is that the page which processes searches knows to expect a comma separated list for this field type and then appears to be parsing out the individual values for searching out web app items with 1 or more matching values. You're right that text fields (string and multiline) just check for 'string contains' matches, and this would be ok if I was only ever needing to search just one value at a time. Here's an example of what I might do:
    Web App item field value (as recorded against the List (Checkbox List) field type:
    8294877,8294878
    Web App Search value (for this same field):
    8294879,8294877,8294885
    The search would return this web app item because the field contains 2 (1 or more) individual values even though they were entered into the search field in a different order. If this web app item were just a Text (string or multiline) field, the searched value is not a substring of the web app item's stored value, so it would not find a match. Hence the need to use Checkbox List field type.
    The web app will have thousands if not 10s of thousands of records, so dumping them all into one big array or object and searching on the front-end won't be practical (though it works great on smaller datasets).

  • Jar file downloaded still the old version

    If I update a new jar file in the web server, The jar file being downloaded by a remote pc is still the old jar file even if the java plugin cache has been deleted. In my source below, I have already specified applet option as plugin.
    Below is the source code for applet caching:
    Hope someone could help thanks
    <OBJECT
    classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="0" height="0" align="baseline" codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
    <PARAM NAME=<%=IboReserved.SCREEN_BUILDER%> VALUE="com.weserv.ibo.gui.InternetBanking">
    <PARAM NAME="trxcode" VALUE="0">
    <PARAM NAME="langind" VALUE="en">
    <PARAM NAME="country" VALUE="US">
    <PARAM NAME="code" VALUE="McpgApplet.class">
    <PARAM NAME="codebase" VALUE="http://mcpgdev.bancnet.net/apps">
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    <PARAM NAME="cache_archive" VALUE="<%= appletArchive %>">
    <PARAM NAME="cache_version" VALUE="<%= appletVersion %>">
    <PARAM NAME="cache_option" VALUE="Plugin">
    <COMMENT>
    <EMBED type="application/x-java-applet;version=1.3"
    width="0" height="0" align="baseline"
    code="McpgApplet" name="mcpgApplet" codebase="http://mcpgdev.bancnet.net/apps"
    pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html">
    <NOEMBED>
    </COMMENT> No Java 2 support for APPLET!! </NOEMBED>
    </EMBED>
    </OBJECT>

    download the zip file unzip it under windows install the drivers you need upgrading
    thats what I did and it updated my video card driver so windows stopped crashing

  • JTable get Old Value in the Listener of change Value

    Software
    JDK 1.5 Update 6
    Requirements
    I have a JTable I want to show the sum total of certain Cell Value.So I have added a TableModelListener by which on updating the cell Value I change the total in the JTextField. The Problem is If I change the value then I have to get the previous value that the cell had. How to get that original value before the update.
    There is a way by which we can get the same by inserting one dummy column which stores previous value.But this method inserts unneccessary if you require the total of 3 columns and if you require the same thing again and again in different frames
    Is There any way by which we can show the total
    Thanks in advance
    CSJakharia

    Can I maintain a sum of a column in a JTextField such that I change the sum as soon as any value in that column is changed without recalculating the totalYes, now I understand the question you just want to update the total with the difference between the old value and the new value.
    I don't see why you are going to all this trouble. Why complicate your program, just loop though all the values in each column and add them together. You will not have a performance problem. Here is a similiar example of this approach:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566133
    However, if you still don't like that solution then you can try overriding the getCellEditor(...) or prepareEditor(...) methods of JTable. These methods should be invoked when you start editing the cell and you could query the TableModel and save the current value.

  • FocusLost event for JTextField sometimes triggered, sometimes not

    Some background.
    A column in a table consists of a number of cells.
    Each cell can be a JTextField or a JComboBox.
    I have written a CellEditor who returns either a JTextField or a JComboBox depending on some conditions.
    The JTextField listens for a FocusLost event to update the database.
    When I leave the first cell the FocusLost event is always triggered.
    For the ther cells the FocusLost event is triggeed every now and then.
    In the mean time I have found a simple workaround by placing the update code in method getCellEditorValue() which is called always by the table when moving to the next cell.
    I am just curious if someone has an explanation for this inconsistent behaviour of the FocusLost event.
    Code is below:
    * QuoteProductPropertyValueEditor.java
    * Created on May 4, 2005
    package tsquote.gui;
    * @author johnz
    import java.awt.Component;
    import java.util.EventObject;
    import java.awt.event.*;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import tsquote.controller.QueryHandler;
    import tsquote.exception.FinderException;
    import tsquote.gui.control.GenericTableModel;
    import tsquote.gui.control.Table;
    import tsquote.util.Messager;
    public class QuoteProductPropertyValueEditor implements TableCellEditor {
          * We use EvetListenerList, because it is thread-safe
         protected EventListenerList listenerList = new EventListenerList();
         protected ChangeEvent changeEvent = new ChangeEvent(this);
         private List<Component> componentList = new ArrayList();
         private Map<Integer, Integer> indexMap = new HashMap(); // maps row to index
         private Table table;
         private int currentRow;
         private QueryHandler queryHandler = QueryHandler.getInstance();
         public QuoteProductPropertyValueEditor() {
              super();
         public Object getCellEditorValue() {
              Component component = componentList.get(indexMap.get(currentRow));
              if (component instanceof JComboBox) {
                   JComboBox comboBox = (JComboBox) component;
                   return comboBox.getSelectedItem();
              JTextField textField = (JTextField) component;
              return textField.getText();
         public Component getTableCellEditorComponent(
                   JTable jTable,
                   Object value,
                   boolean isSelected,
                   int row,
                   int column) {
              final int thisRow = row;
              System.out.println("getTableCellEditorComponent(): thisRow=" + thisRow);
              table = (Table) jTable;
              currentRow = thisRow;
              if (!indexMap.containsKey(thisRow)) {
                   System.out.println("Control added: thisRow=" + thisRow);
                   indexMap.put(thisRow, componentList.size());
                   // This is actually a tsquote.gui.control.Table
                   GenericTableModel genericTableModel = table.getGenericTableModel();
                   List<Map> list = genericTableModel.getList();
                   Map recordMap = list.get(thisRow);
                   Boolean hasList = (Boolean) recordMap.get("product_property.has_list");
                   if (hasList) {
                        JComboBox comboBox = new JComboBox();
                        componentList.add(comboBox);
                        comboBox.addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent event) {
                                  fireEditingStopped();
                        for (int i=0; i<=row +1; i++) {
                             comboBox.addItem("Item" + i);
                   } else {
                        JTextField textField = new JTextField();
                        componentList.add(textField);
                        textField.addFocusListener(new FocusAdapter() {
                             public void focusLost(FocusEvent e) {
                                  System.out.println("textField: thisRow=" + thisRow);
                                  JTextField textField = (JTextField) componentList.get(indexMap.get(thisRow));
                                  String newValue = textField.getText();
                                  fireEditingStopped();
                                  updateQuoteProductProperty(thisRow, newValue);
                        String text = (String) recordMap.get("quote_product_property.value");
                        textField.setText(text);
              Component component = componentList.get(indexMap.get(thisRow));
              if (component instanceof JComboBox) {
                   JComboBox comboBox = (JComboBox) component;
                   if (value == null) {
                        comboBox.setSelectedIndex(0);
                   } else {
                        comboBox.setSelectedItem(value);
              } else {
                   JTextField textField = (JTextField) component;
                   textField.setText((String) value);
              return component;
         private void updateQuoteProductProperty(
                   int row,
                   String newValue) {
              // Get PK quote_prodcut_property from list
              GenericTableModel genericTableModel = table.getGenericTableModel();
              List<Map> list = genericTableModel.getList();
              Map modelRecordMap = list.get(row);
              String storedValue = (String) modelRecordMap.get("quote_product_property.value");
              // If nothing changed, ready
    //          if (storedValue == null) {
    //               if (newValue == null) {
    //                    return;
    //          } else {
    //               if (storedValue.equals(newValue)){
    //                    return;
              // Update model
              modelRecordMap.put ("quote_product_property.value", newValue);
              Integer quoteProductPropertyID = (Integer) modelRecordMap.get("quote_product_property.quote_product_property_id");
              try {
                   queryHandler.setTable("quote_product_property");
                   queryHandler.setWhere("quote_product_property_id=?", quoteProductPropertyID);
                   Map recordMap = queryHandler.getMap();
                   recordMap.put("value", newValue);
                   recordMap.get("quote_product_property.value");
                   queryHandler.updateRecord("quote_product_property", "quote_product_property_id", recordMap);
              } catch (FinderException fE) {
                   Messager.warning("Cannot find record in quote_product_property\n" + fE.getMessage());
         public void addCellEditorListener(CellEditorListener listener) {
              listenerList.add(CellEditorListener.class, listener);
         public void removeCellEditorListener(CellEditorListener listener) {
              listenerList.remove(CellEditorListener.class, listener);
         public void cancelCellEditing() {
              fireEditingCanceled();
         public boolean stopCellEditing() {
              fireEditingStopped();
              return true;
         public boolean isCellEditable(EventObject event) {
              return true;
         public boolean shouldSelectCell(EventObject event) {
              return true;
         protected void fireEditingStopped() {
              CellEditorListener listener;
              Object[] listeners = listenerList.getListenerList();
              for (int i = 0; i < listeners.length; i++) {
                   if (listeners[i] == CellEditorListener.class) {
                        listener = (CellEditorListener) listeners[i + 1];
                        listener.editingStopped(changeEvent);
         protected void fireEditingCanceled() {
              CellEditorListener listener;
              Object[] listeners = listenerList.getListenerList();
              for (int i = 0; i < listeners.length; i++) {
                   if (listeners[i] == CellEditorListener.class) {
                        listener = (CellEditorListener) listeners[i + 1];
                        listener.editingCanceled(changeEvent);
    }

    The JTextField listens for a FocusLost event to update the database.I don't recommend using a FocusListener. Wouldn't you get a FocusLost event even if the user cancels any changes made to the cell?
    Whenver I want to know if data has changed in the table I use a TableModelListener:
    http://forum.java.sun.com/thread.jspa?threadID=527578&messageID=2533071
    I'm not very good at writing cell editors so I don't. I just override the getCellEditor method to return an appropriate editor. Here's a simple example:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableComboBoxByRow extends JFrame
         ArrayList editors = new ArrayList(3);
         public TableComboBoxByRow()
              // Create the editors to be used for each row
              String[] items1 = { "Red", "Blue", "Green" };
              JComboBox comboBox1 = new JComboBox( items1 );
              DefaultCellEditor dce1 = new DefaultCellEditor( comboBox1 );
              editors.add( dce1 );
              String[] items2 = { "Circle", "Square", "Triangle" };
              JComboBox comboBox2 = new JComboBox( items2 );
              DefaultCellEditor dce2 = new DefaultCellEditor( comboBox2 );
              editors.add( dce2 );
              String[] items3 = { "Apple", "Orange", "Banana" };
              JComboBox comboBox3 = new JComboBox( items3 );
              DefaultCellEditor dce3 = new DefaultCellEditor( comboBox3 );
              editors.add( dce3 );
              //  Create the table with default data
              Object[][] data =
                   {"Color", "Red"},
                   {"Shape", "Square"},
                   {"Fruit", "Banana"},
                   {"Plain", "Text"}
              String[] columnNames = {"Type","Value"};
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              JTable table = new JTable(model)
                   //  Determine editor to be used by row
                   public TableCellEditor getCellEditor(int row, int column)
                        int modelColumn = convertColumnIndexToModel( column );
                        if (modelColumn == 1 && row < 3)
                             return (TableCellEditor)editors.get(row);
                        else
                             return super.getCellEditor(row, column);
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              TableComboBoxByRow frame = new TableComboBoxByRow();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

Maybe you are looking for