How to draw a rectangle around the text when I selected the text with the mouse in the "Text" area?

I used

textArea1=new TextArea();
String s=textArea1.getSelectedText();
g.drawRect(s.length(),s.length(),s.length(),s.length());

but it does not work properly.

+3
source share
1 answer

You doubt it. You use the Swing tag, but also use the TextArea text, which is an AWT component, not a Swing component.

I would suggest that you use Swing and use JTextArea. In this case, you can add a "highlight" to the specified. Here is a special class that allows you to use Rectangle Painter for this selection.

+3
source

Source: https://habr.com/ru/post/1762227/


All Articles