Is there an event that ensures that the modelToView call returns the Shape with the latest bounds?
I have a JEditorPane containing some text. Next to the editorpane is a panel, which shows the line numbers. In order to draw the line numbers at the correct position, I need the bounds for the lines. Therefore I get the view of the editorpane and call modelToView for each line, e.g.:
View view = editorPane.getUI().getRootView(editorPane);
Rectangle bounds = view.modelToView(startOffsetOfLine, Position.Bias.Forward, endOffsetOfLine, Position.Bias.Backward, new Rectangle()).getBounds();
In my case sometimes outdated bounds are returned. Is there any listener or event that ensures that modelToView returns the latest bounds?
Wrap the code in a
SwingUtilities.invokeLater(...).This will make sure the code is added to the end of the EDT so it will be processed after all updates to the Document have been made.