简体   繁体   English

更新每个键输入的jtextarea

[英]updates a jtextarea every key input

I want to have 2 JTextAreas. 我想要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??? 是否有可能以及如何在每次用户输入字符时更新第二个textarea? btw, the second textarea will be not editable by the user. 顺便说一下,用户不能编辑第二个textarea。

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);
    }
});

You can get Document from the first JTextArea and set it to the second. 您可以从第一个JTextArea获取Document并将其设置为第二个。 Then make the second one not editable. 然后使第二个不可编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM