will not take operations when cancel the file chooser

This commit is contained in:
huangyuhui 2017-02-26 21:45:39 +08:00
parent 926e276167
commit 0fc7eb6316
4 changed files with 6 additions and 16 deletions

View File

@ -1127,8 +1127,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY); fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY);
fc.setDialogTitle(C.i18n("settings.choose_gamedir")); fc.setDialogTitle(C.i18n("settings.choose_gamedir"));
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.showOpenDialog(this); if (fc.showOpenDialog(this) != JSystemFileChooser.APPROVE_OPTION || fc.getSelectedFile() == null)
if (fc.getSelectedFile() == null)
return; return;
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
@ -1163,8 +1162,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
fc.setFileFilter(new FileNameFilter("javaw.exe")); fc.setFileFilter(new FileNameFilter("javaw.exe"));
fc.addChoosableFileFilter(new FileNameFilter("java.exe")); fc.addChoosableFileFilter(new FileNameFilter("java.exe"));
fc.addChoosableFileFilter(new FileNameFilter("java")); fc.addChoosableFileFilter(new FileNameFilter("java"));
fc.showOpenDialog(this); if (fc.showOpenDialog(this) != JSystemFileChooser.APPROVE_OPTION || fc.getSelectedFile() == null)
if (fc.getSelectedFile() == null)
return; return;
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();

View File

@ -147,7 +147,6 @@
<EmptySpace min="1" pref="1" max="-2" attributes="0"/> <EmptySpace min="1" pref="1" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblRestart" min="-2" max="-2" attributes="0"/> <Component id="lblRestart" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="lblModpack" min="-2" max="-2" attributes="0"/> <Component id="lblModpack" min="-2" max="-2" attributes="0"/>

View File

@ -408,8 +408,7 @@ public class LauncherSettingsPanel extends RepaintPage {
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.setFileFilter(new FileNameExtensionFilter("*.png", "png")); fc.setFileFilter(new FileNameExtensionFilter("*.png", "png"));
fc.addChoosableFileFilter(new FileNameExtensionFilter("*.jpg", "jpg")); fc.addChoosableFileFilter(new FileNameExtensionFilter("*.jpg", "jpg"));
fc.showOpenDialog(this); if (fc.showOpenDialog(this) != JSystemFileChooser.APPROVE_OPTION || fc.getSelectedFile() == null)
if (fc.getSelectedFile() == null)
return; return;
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
@ -486,8 +485,7 @@ public class LauncherSettingsPanel extends RepaintPage {
fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY); fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY);
fc.setDialogTitle(C.i18n("launcher.choose_commonpath")); fc.setDialogTitle(C.i18n("launcher.choose_commonpath"));
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.showOpenDialog(this); if (fc.showOpenDialog(this) != JSystemFileChooser.APPROVE_OPTION || fc.getSelectedFile() == null)
if (fc.getSelectedFile() == null)
return; return;
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();

View File

@ -33,7 +33,7 @@ public class JSystemFileChooser extends JFileChooser {
public JSystemFileChooser() { public JSystemFileChooser() {
super(); super();
} }
public JSystemFileChooser(File f) { public JSystemFileChooser(File f) {
super(f); super(f);
} }
@ -49,15 +49,10 @@ public class JSystemFileChooser extends JFileChooser {
super.updateUI(); super.updateUI();
if (old != null) { if (old != null)
Color background = UIManager.getColor("Label.background");
setBackground(background);
setOpaque(true);
try { try {
UIManager.setLookAndFeel(old); UIManager.setLookAndFeel(old);
} catch (UnsupportedLookAndFeelException ignored) { } catch (UnsupportedLookAndFeelException ignored) {
} }
}
} }
} }