JavaFX项保持为null

时间:2016-01-15 13:13:20

标签: java javafx

我正在尝试为应用程序创建GUI,并且在yourItem.getStatus()加载文件后尝试更改项目时遇到了问题。

一开始我以为我想在项目初始化之前编辑项目(文件的渲染仍在继续,我尝试在完成之前编辑项目)。但后来我尝试制作一个计时器,每秒(为了测试目的这么长时间)检查对象的状态,如果对象不是null,它会做一些事情。

但是我注意到这些项目永远不会为空,因此我无法编辑它们。任何人都知道如何改变这个?到目前为止,我遇到了Text和GridPane对象的这个问题,但没有使用按钮:/

控制器(重要的部分):

fxmlloader

protected void sceneSetter(String filename) { //loads the FXMLFile of the right sceneand makes the scene 1280x720 (720p) try { root = FXMLLoader.load(getClass().getResource(filename)); } catch (IOException e) { System.out.println("RIP scene setting"); } Scene scene = new Scene(root, 1280, 720); //sets the right scene and displays it stage.setScene(scene); stage.show(); if(filename.equals("/InterfaceUserChange.fxml")){ final Timer timer = new Timer(1000, null); timer.addActionListener(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("tried it"); if(firstLoginContainer != null){ TextField field = new TextField() { @Override public void replaceText(int start, int end, String text) { // If the replaced text would end up being invalid, then simply // ignore this call! if (!text.matches("[0-9]*")) { super.replaceText(start, end, text); } } @Override public void replaceSelection(String text) { if (!text.matches("[0-9]*")) { super.replaceSelection(text); } } }; firstLoginContainer.add(field , 1 , 1); timer.stop(); } } }); if(firstLoginContainer == null) { timer.start(); } System.out.println("textfield added?"); } 文件(在边框中):

fxml

0 个答案:

没有答案