Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert text into a Document without triggering insertUpdate()

I want to create a Swing JTextPane that takes action when the user types text into it. But I also want to be able to alter the text in that pane without it treating that alteration as a user typing. How can I do this?

like image 286
Jono Matthews Avatar asked Aug 10 '26 00:08

Jono Matthews


1 Answers

If you don't let update events fire, then chances are that your UI won't get updated either, depending on the actual implementation. So I agree that you might be better off by talking to the event handler, letting it know that the next alteration is going to be a programmatic change. Something like this:

try {
  listener.setProgrammaticChange(true);
  // change document
}
finally {
  listener.setProgrammaticChange(false);
}
like image 84
MvG Avatar answered Aug 12 '26 15:08

MvG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!