AFAIK there is no simple approach to solve this as there is no listener that responds to text selections.
You could however add a CaretListener and whenever the caret is moved check the JTextField to see if any of the text is selected (getSelectedText() returns null if nothing is selected) and if the highlighted state has changed set the button state accordingly.
Sachin H. Gupta
Joined: Oct 10, 2012
what is CaretListener ? I don't know what it does and when it is used. Can you please explain.