Когда я пытаюсь открыть рабочий стол Windows в JFileChooser с помощью Windows L&F, происходит сбой, выдается исключение разрешения или что-то в этом роде.
Я пытался установить начальный каталог для JFileChooser на рабочий стол и результаты те же самые, и я ничего не смог найти в Интернете. Пожалуйста, помогите мне.
Вот метод:
public static void loadFile() {
URL iconPath = GUI.class.getResource("/com/company/textEditor/assets/icon.png");
ImageIcon icon = new ImageIcon(iconPath);
JFrame frame = new JFrame("Editor de textos");
frame.setIconImage(icon.getImage());
JFileChooser fc = new JFileChooser();
while (fc.showOpenDialog(frame) == JFileChooser.CANCEL_OPTION) {
fc.showOpenDialog(frame);
}
String ruta = fc.getSelectedFile().getAbsolutePath();
lPath = ruta;
File file = new File(ruta);
try {
Scanner reader = new Scanner(file);
String data = reader.nextLine();
text = text.concat(data);
while (reader.hasNextLine()) {
data = "\n" + reader.nextLine();
text = text.concat(data);
}
reader.close();
System.out.println(text);
frame = null;
} catch (FileNotFoundException e) {
System.out.println("Something went wrong");
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... on-windows