Skip to content

Commit 1838878

Browse files
committed
Make decompiler settings scrollable
1 parent c666d36 commit 1838878

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/main/java/the/bytecode/club/jda/settings/DecompilerSettings.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
public class DecompilerSettings {
1515
private final Decompiler decompiler;
16-
private final JPanel dialog;
16+
17+
private final JScrollPane dialog;
18+
private final JPanel dialogPane;
1719

1820
/**
1921
* Stores all of the individual settings. Should not be modified after initialization.
@@ -26,11 +28,20 @@ public class DecompilerSettings {
2628

2729
public DecompilerSettings(Decompiler decompiler) {
2830
this.decompiler = decompiler;
29-
this.dialog = new JPanel(new MigLayout("gap rel 0", "grow"));
31+
dialogPane = new JPanel();
32+
dialogPane.setLayout(new MigLayout("gap rel 0", "grow"));
33+
dialog = new JScrollPane(dialogPane);
34+
dialog.setBorder(BorderFactory.createEmptyBorder());
35+
dialog.setPreferredSize(new Dimension(400, 375));
3036
}
3137

3238
public void displayDialog() {
33-
if (JOptionPane.showConfirmDialog(null, dialog, decompiler.getName() + " Settings", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
39+
Dimension oldSize = dialog.getPreferredSize();
40+
if (oldSize.height > dialogPane.getPreferredSize().height)
41+
dialog.setPreferredSize(new Dimension(oldSize.width, dialogPane.getPreferredSize().height));
42+
if (oldSize.width > dialogPane.getPreferredSize().width)
43+
dialog.setPreferredSize(new Dimension(dialogPane.getPreferredSize().width + 50, oldSize.height));
44+
if (JOptionPane.showConfirmDialog(null, dialog, decompiler.getName() + " Settings", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
3445
for (Map.Entry<SettingsEntry, JCheckBox> entry : booleanSettings.entrySet()) {
3546
entry.getKey().set(entry.getValue().isSelected());
3647
}
@@ -43,6 +54,7 @@ public void displayDialog() {
4354
entry.getKey().set(entry.getValue().getValue());
4455
}
4556
}
57+
dialog.setPreferredSize(oldSize);
4658
}
4759

4860
public SettingsEntry getEntry(String key) {
@@ -84,8 +96,8 @@ public void registerSetting(SettingsEntry entry) {
8496
throw new IllegalArgumentException();
8597
}
8698

87-
dialog.add(item, "align right");
88-
dialog.add(new JLabel(entry.key), "wrap");
99+
dialogPane.add(item, "align right");
100+
dialogPane.add(new JLabel(entry.key), "wrap");
89101
}
90102

91103
public void loadFrom(JsonObject rootSettings) {

0 commit comments

Comments
 (0)