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

View File

@ -147,7 +147,6 @@
<EmptySpace min="1" pref="1" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblRestart" min="-2" max="-2" attributes="0"/>
<EmptySpace 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.setFileFilter(new FileNameExtensionFilter("*.png", "png"));
fc.addChoosableFileFilter(new FileNameExtensionFilter("*.jpg", "jpg"));
fc.showOpenDialog(this);
if (fc.getSelectedFile() == null)
if (fc.showOpenDialog(this) != JSystemFileChooser.APPROVE_OPTION || fc.getSelectedFile() == null)
return;
try {
String path = fc.getSelectedFile().getCanonicalPath();
@ -486,8 +485,7 @@ public class LauncherSettingsPanel extends RepaintPage {
fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY);
fc.setDialogTitle(C.i18n("launcher.choose_commonpath"));
fc.setMultiSelectionEnabled(false);
fc.showOpenDialog(this);
if (fc.getSelectedFile() == null)
if (fc.showOpenDialog(this) != JSystemFileChooser.APPROVE_OPTION || fc.getSelectedFile() == null)
return;
try {
String path = fc.getSelectedFile().getCanonicalPath();

View File

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