今天我重新加载了Java 8和NetBeans 8.安装JDK和NetBeans之后,我看了一下我的项目。当我运行它时,我的标签有一个更大的字体,按钮更大,我的ComboBox没有通过.txt文件获取其项目。在旧版本的Java 7.xx(JavaFx 2.2)上没有问题,我的Label和Buttons的大小正常,我的控制器可以填充我的ComboBox。我在代码中没有改变,所以它应该工作.... 可能是什么问题?我找不到谷歌或其他社区的答案。 感谢您的帮助:)
登录-FXML
<GridPane fx:id="loginWindow" fx:controller="homenizer.controller.LoginController"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<padding>
<Insets top="25" right="25" bottom="10" left="25"/>
</padding>
<stylesheets>
<URL value="@/homenizer/view/css/LoginCSS.css"/>
</stylesheets>
<Label fx:id="welcomeText" text="Willkommen"
GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="2" />
<Label fx:id="username" text="Benutzername"
GridPane.columnIndex="0" GridPane.rowIndex="1" />
<ComboBox fx:id="selectUser" editable="true"
GridPane.columnIndex="1" GridPane.rowIndex="1" minWidth="180"
onAction="#onMenuRequest" />
<Button fx:id="start" text="starten"
GridPane.columnIndex="1" GridPane.rowIndex="2"
minHeight="25" textAlignment="CENTER"
onAction="#onStartRequest" />
<Button fx:id="createUser" text="Benutzer erstellen"
GridPane.columnIndex="1" GridPane.rowIndex="2"
GridPane.halignment="RIGHT"
minHeight="25" textAlignment="CENTER"
onAction="#onCreateUserRequest" />
<Label fx:id="startStat"
GridPane.columnIndex="0" GridPane.rowIndex="3" GridPane.columnSpan="2" />
登录控制(摘要)
//Benutzer erstellen Button wird gedrückt
@FXML
private void onCreateUserRequest(ActionEvent e){
String username = (String) selectUser.getValue();
if(selectUser.getItems().contains(username)){
showStat(Color.RED,"Benutzername schon vorhanden"); // nicht erflogriech
}else{
try {
RandomAccessFile raf = new RandomAccessFile("src/homenizer/profiles/userlist.txt", "rw");
File dir = new File("src/homenizer/profiles/"+username);
dir.mkdir();
raf.seek(raf.length()); //Ende der Datei suchen
raf.writeBytes(username+"\r\n"); //Benutzernamen am Ende der speichern und Zeilenumbruch ausgeben
userID = new UserID(username);
userID.save();
selectUser.getItems().add(username);
showStat(Color.GREEN, "Benutzer erfolgreich angelegt"); //erfolgreich
raf.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
//ComboBox Inhalt wir ausgegeben
@FXML
private void onMenuRequest(ActionEvent e){
try {
RandomAccessFile userlist = new RandomAccessFile("src/homenizer/profiles/userlist.txt", "rw");
while(userlist.getFilePointer() != userlist.length()){
String username = userlist.readLine();
if(!(selectUser.getItems().contains(username)))
selectUser.getItems().add(username); //Einträge in ComboBox einfügen
}
} catch (FileNotFoundException ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
}
}
例如,onCreateUserRequest工作正常,但我的ComBox不再显示所有已创建的用户。使用Java 7.xx(JavFx 2.2)它可以工作吗?
编辑:好的,大标签和按钮的问题已经解决了。我将字体设置为另一个较小的尺寸,并且没有一切看起来很好,但仍然会出现组合框问题。