MTextField modification updates other MTextFields

20 views Asked by At

I have three MTextFields next to each other and i want to achieve an automatic input split when a user pastes something from the clipboard into the first text field.

So for example we have this String in the clipboard: AB1234-12345678

Then the string is split into AB - 1234 - 12345678

The splitting works fine, but i get a very weird bug:

As soon as i delete the third field, then the second field and then only touch the first field with my mouse the number in the second field (1234) re-appears. Even though i used a KeyListener.. here is my code that splits the string:

public class Splitter implements KeyListener {
        public void splitInputString(String input) {
          input = input.replace("some replacements"); 
          String firstPart = input.substring(0, 2);
          String secondPart= input.substring(2, 6);
          String thirdPart= input.substring(6, 14);
    
          updateDoField(firstDoField, firstPart); 
          updateDoField(secondDoField, secondPart); 
          updateDoField(thirdDoField, thirdPart); 
    
    
          updateMTextField(firstTextField, firstPart);
          updateMTextField(secondTextField, secondPart);
          updateMTextField(thirdTextField, thirdPart);
    }
    @Override
    public void keyPressed(KeyEvent e) {
        if ((e.keyCode == KeyIdentifier.V_KEYCODE) && (e.stateMask == KeyIdentifier.CTRL_MASK)) {
        splitInputString(firstTextField.getText());
    }
@Override
public void keyReleased(KeyEvent e) {
        if ((e.keyCode == KeyIdentifier.V_KEYCODE) && (e.stateMask == KeyIdentifier.CTRL_MASK)) {
        splitInputString(firstTextField.getText());
    }

}

And this class i called by following code inside another class:

  getView().getField()
.addKeyListener(new Splitter(firstMTextField, secondMTextField, thirdMTextField, 2, 6, 14, firstDoField, secondDoField, thirdDoField));

I debugged the code and the amount of calls is correct, meaning that it only gets called when there is the ctrl + v event in the first text box, it is never called again so i dont understand why it fills the second text field when i modify the first (by not even a ctrl v event) ?

0

There are 0 answers