Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javafx";网格已在场景图形中,不能设置为根“;错误_Java_Javafx_Grid_Javafx 8 - Fatal编程技术网

Javafx";网格已在场景图形中,不能设置为根“;错误

Javafx";网格已在场景图形中,不能设置为根“;错误,java,javafx,grid,javafx-8,Java,Javafx,Grid,Javafx 8,我正在构建一个计算器,我希望它能够为用户在简单和科学的布局之间切换。它适用于“简单”场景。然而,当我试图将场景切换到“科学”时,它给了我标题的错误。我试图设置一个边框窗格作为包装,然后在顶部放置一个“设置”按钮,在中间放置一个网格窗格 我没有设置任何根。我知道它在默认情况下必须将某些内容设置为root,但我发布了这个问题,因为我不理解错误。我相信它在添加BorderPane的外包装之前就已经起作用了。你能帮我理解我做错了什么以及如何纠正它吗 这是一个完整的错误,顺便说一句: Exception

我正在构建一个计算器,我希望它能够为用户在简单和科学的布局之间切换。它适用于“简单”场景。然而,当我试图将场景切换到“科学”时,它给了我标题的错误。我试图设置一个边框窗格作为包装,然后在顶部放置一个“设置”按钮,在中间放置一个网格窗格

我没有设置任何根。我知道它在默认情况下必须将某些内容设置为root,但我发布了这个问题,因为我不理解错误。我相信它在添加BorderPane的外包装之前就已经起作用了。你能帮我理解我做错了什么以及如何纠正它吗

这是一个完整的错误,顺便说一句:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Grid hgap=10.0, vgap=8.0, alignment=TOP_LEFTis already inside a scene-graph and cannot be set as root
    at javafx.scene.Scene$9.invalidated(Scene.java:1100)
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:111)
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
    at javafx.scene.Scene.setRoot(Scene.java:1072)
    at javafx.scene.Scene.<init>(Scene.java:347)
    at javafx.scene.Scene.<init>(Scene.java:223)
    at Calculator.CreateScientific(Calculator.java:198)
    at Calculator.lambda$1(Calculator.java:51)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    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:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    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:394)
    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$353(GlassViewEventHandler.java:432)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
    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$147(WinApplication.java:177)
    at java.lang.Thread.run(Unknown Source)
你有:

scientificPane.setBottom(scientficGrid);
紧接着是:

scientificScene = new Scene(scientificGrid, 600, 600);
这使得
scientificGrid
既是
scientificPane
的子级,又是
scientificScene
的根级,因此出现了错误。你可能想打电话:

scientificScene = new Scene(scientificPane, 600, 600);

不要使用IDE标记,如果您只是使用。仅当您对该IDE有特定问题时才使用IDE标记。您可以调用
scientificPane.setBottom(scientificGrid)
,然后立即调用
新场景(scientificGrid,600600)
。第一个参数将是新创建的
场景的根,但您已经将该节点添加到
边框窗格中。也许你想通过
科学版
?谢谢你。原来我只是粗心地打字。如果你把它写下来作为答案,我会接受它作为正确答案。
public class ConfirmBox {

    static Boolean answer = false;

    public static Boolean display(String title, String message) {
        Stage window = new Stage();

        window.initModality(Modality.APPLICATION_MODAL);
        window.setTitle(title);
        window.setMinWidth(250);

        Label label = new Label("Settings");
        label.setText(message);

        Button yes = new Button("Yes");

        Button no = new Button("No");

        yes.setOnAction(e -> {
            answer = true;
            window.close();
        });

        no.setOnAction(e -> {
            answer = false;
            window.close();
        });

        HBox questionLayout = new HBox(10);
        questionLayout.getChildren().add(label);

        HBox answerLayout = new HBox(10);
        answerLayout.getChildren().addAll(yes, no);

        BorderPane borderPane = new BorderPane();
        borderPane.setTop(questionLayout);
        borderPane.setLeft(answerLayout);

        Scene scene = new Scene(borderPane);
        window.setScene(scene);
        window.showAndWait();

        return answer;
    }
}
scientificPane.setBottom(scientficGrid);
scientificScene = new Scene(scientificGrid, 600, 600);
scientificScene = new Scene(scientificPane, 600, 600);