How to force an event executor to execute the latter in java?

I have a JTextPane that has a DocumentListener awaiting changes to the underlying HTML document. When the content changes, the event uses JTextPane.scrollToReference to move the view to a specific reference anchor. The problem is that the underlying View in JTextPane also listens for document changes and is not updated until my listener executes, which raises an exception. Is there a way to get my DocumentListener to execute after any other event listener for this particular event? Or can I somehow wait for the view to refresh before my code runs?

+3
source share
3 answers

I had to extend the Viewport and JScrollPane classes to accomplish this. I set the listener for the view change event and added my own logic there (which ensured that this was the last code executed in the rendering chain).

0
source

First try using SwingUtilities.invokeLater () for the listener, which should be executed as the last. If this does not work, create your own priority queue.

+6
source
  • JTextComponents, , Listeners, ,

  • , , , JViewport

  • no idea whats Listener , DocumentListener (,) FocusListener (e.i.) RepaintManager

  • remove Listener, generating exceptions, add Listener, if it is really necessary, remove uselles Listeners immediately,

  • Download without any warranties of listeners, as well as events from multi-user listeners betweens model_to_view and vice versa

  • you can test if Listeners fire events subsequently or gradually by clicking on the necessary event from the Swing Action (delayed by the Swing timer) or for asynchronous listeners (frozen) Thread.sleep (int)

+1
source

All Articles