Changing Label Highlights TextField Contents

(Apple bug # 3305682)

Changing a Label and calling invalidate/validate causes the TextField contents to be highlighted.  This can result in one or more characters being deleted from the TextField.  To reproduce this problem do the following:
  1. Highlight the text in the TextField (if it is not already highlighted) and type the single character "2".  The number appears in the TextField, selected, and the Label text is changed to "Updated Label".
  2. Type the single character 3.  It replaces the 2, which was highlighted but it does not get highlighted since the Label does not change.
  3. Type the single character 4.  It is added after the 3 in the TextField, which now reads "34".  

Expected behavior:  The 2 should not have been highlighted and the full "234" sequence should appear in the TextField.  This is the behavior under all versions previous to 141DP102.

    If you have any insights, workarounds or comments about this test page please contact Mickey Segal.  A listing of  many Java resources is at this link.

Source code:

import java.applet.*;
import java.awt.*;
import java.awt.event.*; 

public class PoofChar extends Applet implements KeyListener {

TextField textField;
Label textFieldLabel;

public void init() 
{
    setBackground(new Color(225,225, 255));
    textField = new TextField("Initial chars"); 
    textField.addKeyListener(this);
    add(textField);
    textFieldLabel = new Label("Initial label");
    add(textFieldLabel);
}

public void keyPressed(KeyEvent ke){}

public void keyReleased(KeyEvent ke)
{
    textFieldLabel.setText("Updated label");
    textFieldLabel.invalidate();
    invalidate();
    validate();
}

public void keyTyped(KeyEvent ke){}

} // END OF Class PoofChar