java - JTextArea, JTextField, how to replace text from the caret to the left with another string -


i'm making text processing program, , want if user press 'a' ('a' demonstration, have list of special characters that), replace characters caret left string.

i have tried "settext" method replaced moved caret , text component scrolled end, want caret not move anywhere else , text component not scroll end, how can code that(i overriding processkeyevent)?

any appreciated.

try use document filter:

    jtextarea textarea = new jtextarea();      ((abstractdocument) textarea.getdocument()).setdocumentfilter(new documentfilter() {                     @override         public void replace(filterbypass fb, int offset, int length, string text, attributeset attrs)                 throws badlocationexception {              if ("a".equals(text)) {                 text = "b";             }                             super.replace(fb, offset, length, text, attrs);         }     }); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -