Skip to content

Commit

Permalink
Fix Installer when using Nimbus LookAndFeel (#15)
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
AterAnimAvis authored Feb 9, 2024
1 parent ebd0a89 commit d802881
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/main/java/net/minecraftforge/installer/ui/InstallerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void updateFilePath()
Action action = actions.get(choiceButtonGroup.getSelection().getActionCommand()).apply(null);
TargetValidator.ValidationResult valid = action.getTargetValidator().validate(targetDir);

if (profile.getMirror() != null)
if (profile.getMirror() != null && profile.getMirror().isAdvertised())
{
sponsorButton.setText(action.getSponsorMessage());
sponsorButton.setToolTipText(profile.getMirror().getHomepage());
Expand Down Expand Up @@ -304,22 +304,13 @@ public void run(ProgressCallback monitor)
languageBox.setSelectedItem(known.stream().filter(locate -> locate.locale.equals(current)).findFirst().orElse(known.get(0)));
languageBox.addActionListener(e -> TRANSLATIONS.setLocale(((L10nManager.LocaleSelection)languageBox.getSelectedItem()).locale, true));

JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[] {
TRANSLATIONS.button("installer.button.proceed"), TRANSLATIONS.button("installer.button.cancel"), languageBox
});

// Attempt to change the OK button to a Proceed button
// Use index 1 (the buttons panel) as 0 is this panel
final JPanel buttonPanel = (JPanel) optionPane.getComponents()[1];
final List<JButton> buttons = Arrays.stream(buttonPanel.getComponents())
.filter(comp -> comp instanceof JButton)
.map(JButton.class::cast)
.collect(Collectors.toList());
if (buttons.size() == 2) {
proceedButton = Optional.of(buttons.get(0));
buttons.get(0).addActionListener(e -> optionPane.setValue(JOptionPane.OK_OPTION));
buttons.get(1).addActionListener(e -> optionPane.setValue(JOptionPane.OK_CANCEL_OPTION));
}
JButton proceedButton = TRANSLATIONS.button("installer.button.proceed");
JButton cancelButton = TRANSLATIONS.button("installer.button.cancel");
JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[] { proceedButton, cancelButton, languageBox });

proceedButton.addActionListener(e -> optionPane.setValue(JOptionPane.OK_OPTION));
cancelButton.addActionListener(e -> optionPane.setValue(JOptionPane.OK_CANCEL_OPTION));
this.proceedButton = Optional.of(proceedButton);

dialog = optionPane.createDialog("");
TRANSLATIONS.translate(dialog, new TranslationTarget<>(Dialog::setTitle), "installer.window.title", profile.getProfile());
Expand Down

0 comments on commit d802881

Please sign in to comment.