我不知道为什么,但是如果我单击“提交”或“取消”,则会打开showOpenDialog()
的第二个窗口。我尝试过JFileChooser
,但存在相同的问题。
private void menuAction(ActionEvent event) throws IOException {
FileChooser file = new FileChooser();
file.setTitle("Suche eine Datei");
try {
do {
String row;
File userDir = new File("/home/tom/Dokumente/Lernfragen");
file.setInitialDirectory(userDir);
File selected = file.showOpenDialog(null);
if (selected != null){
FileReader getData = new FileReader(selected);
BufferedReader br = new BufferedReader(getData);
this.questions = new ArrayList();
this.answers = new ArrayList();
while ((row = br.readLine()) != null){
if (row.contains("Q:"))
if (!spacesToQA(row).equals(""))
this.questions.add(spacesToQA(row));
if (row.contains("A:"))
if (!spacesToQA(row).equals(""))
this.answers.add(spacesToQA(row));
}
txtAsk.setText(this.questions.get(rnd.nextInt(this.questions.size()-1)));
} else{
System.out.println("Keine Datei angegeben!");
break;
}
} while ((this.answers.size() != this.questions.size()));
} catch (FileNotFoundException e) {
System.out.println("null !");
}
}
亲切的问候。
答案 0 :(得分:0)
我的问题是这个
<Menu mnemonicParsing="false" onAction="#menuAction" text="File">
<items>
<MenuItem mnemonicParsing="false" onAction="#menuAction" text="Laden" fx:id="menuItemLoad" />
<MenuItem mnemonicParsing="false" text="Schließen" fx:id="menuItemClose" />
</items>
</Menu>
在这种情况下,我有2个onAction属性。问题已解决,感谢您的快速解答。
亲切的问候