Welcome to the Ranch
So
what happens? Do you select only text between successive _ characters? That may be an operating system feature, in which case you may not be able to change that behaviour. You can probably highlight a block of text with ctrl‑click or shift‑click or by dragging the mouse.
Not sure myself. Does the
Java™ Tutorials section←(
Link. Note it is in 3 parts and the left margin contains links to other text classes.) say anything about clicking text? Answer: not a lot. It does mention selecting text and getSelectedText methods. If you go through the
JTextComponent documentation, you find there are various listeners you can add to one, but action listener doesn't seem to be among them.
Mouse listeners are maybe not a good idea because they are too low level. You can add an associated button and give that an action listener. You can use a key binding to associate an action with pushing a particular key, e.g. shift, ctrl‑shift, ctrll‑
f10, or whatever you want. Some of the links in the Java™ Tutorials section will take you there.