title: Setting field based on validated other fields
body: <p>Suppose I have a JDialog with 3 text fields First, Last and LastFirst. When LastFirstreceives the focus it is to be set as the concatenation of first &amp; last, but only if first &amp; last are not empty. Here's pertinent code from my example, which doesn't work:
  What am I missing?</p>
  
  <pre><code>import java.awt.Container;
  import java.awt.GridLayout;
  import javax.swing.JOptionPane;
  public class FieldValidatedSetting extends javax.swing.JFrame {
  private javax.swing.JTextField txtFirst;
  private javax.swing.JTextField txtLast;
  private javax.swing.JTextField txtLastFirst;
  // 
  //This is supposed to concatenate Last &amp; First and set LastFirst. 
  // Empty   First or Last fields should result in a message dialog
  // and return for user correction. Problem is it issues the message twice!
  // Please excuse the crummy layout./
  // Constructor  
  private void txtLastFirstFocusGained(java.awt.event.FocusEvent evt)                                              
  if(txtLast.getText().isEmpty() || txtFirst.getText().isEmpty()){
          JOptionPane.showMessageDialog(null, "You must enter First &amp; Last");
          txtFirst.requestFocusInWindow();
      } else{
          txtLastFirst.setText(txtLast.getText()  +  txtFirst.getText());
      }
  }             
  
  public FieldValidatedSetting() {
  txtFirst = new javax.swing.JTextField();
  txtLast = new javax.swing.JTextField();
  txtLastFirst = new javax.swing.JTextField();
  
  txtLastFirst.addFocusListener(new java.awt.event.FocusAdapter() {
  public void focusGained(java.awt.event.FocusEvent evt) {
              txtLastFirstFocusGained(evt);
  }
  });
  Container pane = getContentPane();
  pane.setLayout(new GridLayout(1, 3));
  pane.add(txtFirst);
  pane.add(txtLast);
  pane.add(txtLastFirst);
  pack();
  }
  public static void main(String args[]) {
  java.awt.EventQueue.invokeLater(new Runnable() {
  public void run() {
  new FieldValidatedSetting().setVisible(true);
  }
  });
  }
  }
  </code></pre>