How to work with selected text in JTextArea ?
Example: user selected text in JTextArea pressed a button and something happened with this selected text, for example, it was replaced with "TEST"
For this, the replaceSelection() method is replaceSelection() :
JButton butt = new JButton("Replace"); JTextArea area = new JTextArea(); butt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { area.replaceSelection("TEST"); } }); Result of work:
Source: https://ru.stackoverflow.com/questions/472700/
All Articles