根窗格,父窗格和窗格窗格如何将其加载到根窗格或父窗格中

时间:2017-07-27 13:02:52

标签: java javafx javafx-2 javafx-8 fxml

这个问题不一样,因为我要求加载到不同的父级,这会导致错误 这里在我的情况下有根窗格,父窗格和子假设一些fxml(名称为更新)文件加载到子(stackpane名称是stackcountry)如果我尝试将此子项添加到父堆栈(堆栈名称为Stackconsearch)或root堆栈(堆栈名称为Stackhome)它会在

处抛出错误
     Stackconsearch.getChildren().clear();//this is parent
                Stackconsearch.getChildren().add(root); 

       stackhome.getChildren().clear();
                stackhome.getChildren().add(root); //this is root or grandparent

当用户点击tableView new fxml弹出窗口的任何数据时,我试图将它添加到根窗格(stackhome是祖父/ root)时会抛出错误但是如果尝试将其添加到子堆栈(stackcountry)然后它正常工作

     tableUser.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
         tableUser.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<addcountryController>() {
         public void onChanged(ListChangeListener.Change<? extends addcountryController> c) {
             try {



                    FXMLLoader loader =new FXMLLoader();
   loader.load(getClass().getResource("/region/updatecountry.fxml").openStream());

                 updatecountryController usercontroller=(updatecountryController)loader.getController();
                    for (addcountryController p : c.getList()) {
                     String ADDID=p.getId();
                     String ADD=p.getName();    
                     String ADD1=p.getDescriptionshort();
                     String ADD2=p.getDescription();
                     String ADD3=p.getCountrychar();
                     usercontroller.setText(ADDID,ADD,ADD1,ADD2,ADD3);
                   }
                    Pane root = loader.getRoot();                       
                    stackhome.getChildren().clear();
                    stackhome.getChildren().add(root);                      

             } catch (IOException e) {
                e.printStackTrace();
             }

此场景类似于祖父(stackhome),父(stackconsearch)和子(stackcountry)。当我将它添加到子级时fxml正确加载但是如果我尝试将其添加到父级或祖父级上则会抛出错误

            Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at regionController.countryController$1.onChanged(countryController.java:127)
at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.callObservers(ReadOnlyUnbackedObservableList.java:75)
at javafx.scene.control.TableView$TableViewArrayListSelectionModel.handleSelectedCellsListChangeEvent(TableView.java:3077)
at javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearAndSelect(TableView.java:2423)
at javafx.scene.control.TableView$TableViewSelectionModel.clearAndSelect(TableView.java:1914)
at com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.simpleSelect(TableCellBehaviorBase.java:215)
at com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.doSelect(TableCellBehaviorBase.java:197)
at com.sun.javafx.scene.control.behavior.CellBehaviorBase.mousePressed(CellBehaviorBase.java:150)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:95)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案