|
27 | 27 | */
|
28 | 28 | package mekhq.gui.dialog;
|
29 | 29 |
|
30 |
| -import megamek.client.ui.swing.util.UIUtil; |
31 |
| -import megamek.logging.MMLogger; |
32 |
| -import mekhq.campaign.Campaign; |
33 |
| - |
34 |
| -import javax.swing.*; |
35 |
| -import javax.swing.event.HyperlinkEvent.EventType; |
36 |
| -import java.awt.*; |
37 |
| -import java.awt.event.WindowAdapter; |
38 |
| -import java.awt.event.WindowEvent; |
39 |
| - |
40 | 30 | import static java.lang.Math.round;
|
41 | 31 | import static javax.swing.BorderFactory.createEmptyBorder;
|
42 | 32 | import static megamek.client.ui.swing.util.FlatLafStyleBuilder.setFontScaling;
|
43 | 33 | import static mekhq.gui.baseComponents.immersiveDialogs.ImmersiveDialogCore.handleImmersiveHyperlinkClick;
|
44 | 34 | import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
|
45 | 35 | import static mekhq.utilities.MHQInternationalization.isResourceKeyValid;
|
46 | 36 |
|
| 37 | +import java.awt.BorderLayout; |
| 38 | +import java.awt.Dimension; |
| 39 | +import java.awt.Point; |
| 40 | +import java.awt.event.WindowAdapter; |
| 41 | +import java.awt.event.WindowEvent; |
| 42 | +import javax.swing.JDialog; |
| 43 | +import javax.swing.JEditorPane; |
| 44 | +import javax.swing.JPanel; |
| 45 | +import javax.swing.JScrollPane; |
| 46 | +import javax.swing.SwingUtilities; |
| 47 | +import javax.swing.event.HyperlinkEvent.EventType; |
| 48 | + |
| 49 | +import megamek.client.ui.swing.util.UIUtil; |
| 50 | +import megamek.logging.MMLogger; |
| 51 | +import mekhq.campaign.Campaign; |
| 52 | + |
47 | 53 | /**
|
48 | 54 | * The {@code GlossaryDialog} class represents a dialog window for displaying glossary entries. It displays detailed
|
49 | 55 | * information about a glossary term, including its title and description, in a styled HTML format.
|
@@ -127,13 +133,15 @@ private void buildDialog(String key) {
|
127 | 133 | // Add a HyperlinkListener to capture hyperlink clicks
|
128 | 134 | editorPane.addHyperlinkListener(evt -> {
|
129 | 135 | if (evt.getEventType() == EventType.ACTIVATED) {
|
130 |
| - handleImmersiveHyperlinkClick(parent, campaign, evt.getDescription()); |
| 136 | + handleImmersiveHyperlinkClick(this, campaign, evt.getDescription()); |
131 | 137 | }
|
132 | 138 | });
|
133 | 139 |
|
134 | 140 | // Wrap the JEditorPane in a JScrollPane
|
135 | 141 | JScrollPane scrollPane = new JScrollPane(editorPane);
|
136 | 142 | scrollPane.setMinimumSize(new Dimension(CENTER_WIDTH, scrollPane.getHeight()));
|
| 143 | + // This line ensures the scroll pane starts scrolled to the top, not bottom. |
| 144 | + SwingUtilities.invokeLater(() -> scrollPane.getViewport().setViewPosition(new Point(0, 0))); |
137 | 145 |
|
138 | 146 | // Create a JPanel with padding
|
139 | 147 | JPanel paddedPanel = new JPanel(new BorderLayout());
|
|
0 commit comments