|
30 | 30 | package org.scijava.ui.swing.widget;
|
31 | 31 |
|
32 | 32 | import java.io.IOException;
|
| 33 | +import java.util.Objects; |
33 | 34 |
|
34 | 35 | import javax.swing.JEditorPane;
|
35 | 36 | import javax.swing.JPanel;
|
@@ -124,6 +125,24 @@ public boolean supports(final WidgetModel model) {
|
124 | 125 | @Override
|
125 | 126 | public void doRefresh() {
|
126 | 127 | // maybe dialog owner changed message content
|
127 |
| - pane.setText(get().getText()); |
| 128 | + String text = get().getText(); |
| 129 | + if (!Objects.equals(htmlify(text), pane.getText())) { |
| 130 | + // NB: Only change the text if it actually changed. |
| 131 | + // This avoids triggering a scrollRectToVisible-type behavior where the |
| 132 | + // containing scroll pane's view gets adjusted to include this text area. |
| 133 | + // Not sure if it's a bug, strictly speaking, but it causes undesirable |
| 134 | + // sudden scrolling, as reported in scijava/scijava-ui-swing#74. |
| 135 | + pane.setText(text); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + // HACK: Normalize text to final HTML representation |
| 140 | + // by feeding it through a dummy JEditorPane instance. |
| 141 | + private JEditorPane dummy; |
| 142 | + private String htmlify(String text) { |
| 143 | + if (text == null) return null; |
| 144 | + if (dummy == null) dummy = new JEditorPane("text/html", ""); |
| 145 | + dummy.setText(text); |
| 146 | + return dummy.getText(); |
128 | 147 | }
|
129 | 148 | }
|
0 commit comments