title: Use Case: Append text to JTextField by double clicking the items in JList
body: <p>I have 2 JTextFields (JTextField1 and JTextField2) to which text has to appended from JList. <a href="https://i.stack.imgur.com/i3029.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i3029.png" alt="enter image description here"></a></p>
  
  <p>Use case is, after I finish typing in JTextField1 and double click the arguement in Jlist, it has to be appended to the JTextField1 since that was the last area of focus from the keyboard. The same case with JTextField2.</p>
  
  <p>Code:</p>
  
  <pre><code>jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
  
  public void focusLost(java.awt.event.FocusEvent evt) 
  {
      if (lista1.size()&gt;0)
         {
          MouseListener mouseListener2 = new MouseAdapter() 
           {          
          @Override
           public void mouseClicked(MouseEvent mouseEvent) 
            {
  
             JList varList = (JList) mouseEvent.getSource();
             if (mouseEvent.getClickCount() == 2) 
                  {                        
                   int index = varList.locationToIndex(mouseEvent.getPoint());
                   if (index &gt;= 0) 
                     {
                      Object o2 = varList.getModel().getElementAt(index);
                      String prefClassLabel =  jTextField1.getText().trim();   
  
                      jTextField1.setText("test" );                                     
                      }  
                  }
             }
  
           };
           argVariables_List.addMouseListener(mouseListener2);
        }       
  
      }
      });
  </code></pre>
  
  <p>I wrote an exact similar function for jTextField2. But still when I double click the text from the jList, it gets appended to both the jTextFields instead of the last focussed jTextField. Please suggest me on what is the mistake.</p>