Skip to content

Commit 85d8b7d

Browse files
committed
Fixed Scroll Pane Start Position in Glossary Dialogs; Corrected Reference in Progressive Dialogs
- Ensured the GlossaryDialog's scroll pane defaults to the top position on load. - Corrected `handleImmersiveHyperlinkClick` to use the correct reference (`this` instead of `parent`).
1 parent 3715c19 commit 85d8b7d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

Diff for: MekHQ/src/mekhq/gui/dialog/GlossaryDialog.java

+19-11
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,29 @@
2727
*/
2828
package mekhq.gui.dialog;
2929

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-
4030
import static java.lang.Math.round;
4131
import static javax.swing.BorderFactory.createEmptyBorder;
4232
import static megamek.client.ui.swing.util.FlatLafStyleBuilder.setFontScaling;
4333
import static mekhq.gui.baseComponents.immersiveDialogs.ImmersiveDialogCore.handleImmersiveHyperlinkClick;
4434
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
4535
import static mekhq.utilities.MHQInternationalization.isResourceKeyValid;
4636

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+
4753
/**
4854
* The {@code GlossaryDialog} class represents a dialog window for displaying glossary entries. It displays detailed
4955
* information about a glossary term, including its title and description, in a styled HTML format.
@@ -127,13 +133,15 @@ private void buildDialog(String key) {
127133
// Add a HyperlinkListener to capture hyperlink clicks
128134
editorPane.addHyperlinkListener(evt -> {
129135
if (evt.getEventType() == EventType.ACTIVATED) {
130-
handleImmersiveHyperlinkClick(parent, campaign, evt.getDescription());
136+
handleImmersiveHyperlinkClick(this, campaign, evt.getDescription());
131137
}
132138
});
133139

134140
// Wrap the JEditorPane in a JScrollPane
135141
JScrollPane scrollPane = new JScrollPane(editorPane);
136142
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)));
137145

138146
// Create a JPanel with padding
139147
JPanel paddedPanel = new JPanel(new BorderLayout());

0 commit comments

Comments
 (0)