Tuesday, March 8, 2022

Java: Get raw text in JFormattedTextField

You could define a custom class that derives from JFormattedTextField and use KeyListener to get the raw text that the user is typing:

public class MyFormattedTextField extends JFormattedTextField {
private String rawText;
private class MyKeyListener implements KeyListener {
...
@Override
public void keyTyped(KeyEvent e) {
rawText = getText();
}
}
public MyFormattedTextField() {
addKeyListener(new MyKeyListener());
}
public String getRawText() {
return rawText;
}
}
view raw getRawText.java hosted with ❤ by GitHub

No comments:

Post a Comment