Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updates a jtextarea every key input

I want to have 2 JTextAreas. the first one is where the user types in and the second one is where the binary equivalent of the input will appear. Is it possible and how to make the second textarea updates everytime the user inputs a character??? btw, the second textarea will be not editable by the user.

like image 669
Kopaka Avatar asked Jul 28 '26 05:07

Kopaka


2 Answers

Add a change listener on the document of the first the first text area.

jTextArea1.getDocument().addDocumentListener(new DocumentListener() {
    @Override
    public void changedUpdate(DocumentEvent evt) {
        dumpBinary(evt, jTextArea2);
    }
    @Override
    public void insertUpdate(DocumentEvent evt) {
        dumpBinary(evt, jTextArea2);
    }
    @Override
    public void removeUpdate(DocumentEvent evt) {
        dumpBinary(evt, jTextArea2);
    }
});
like image 174
Joop Eggen Avatar answered Jul 30 '26 19:07

Joop Eggen


You can get Document from the first JTextArea and set it to the second. Then make the second one not editable.

like image 27
StanislavL Avatar answered Jul 30 '26 18:07

StanislavL