int end = pane.getSelectionEnd();
pane.setSelectionStart(end);
pane.setSelectionEnd(end);
Deselect the selected text and leave the caret at the end of what was selected by the user. He might pay pop JOptionPanetelling the user why the choice has disappeared.
JOptionPane.showMessageDialog(
null,
"Don't select swear words!",
"Net Nanny says..",
JOptionPane.ERROR_MESSAGE);
source
share