简体   繁体   English

JavaFX 在场景中嵌入场景

[英]JavaFX embed scene in scene

I have an application that uses a javafx Scene to render something, and I want to put that rendering into some GUI that I made, also in javafx.我有一个应用程序,它使用 javafx 场景来渲染某些东西,我想将该渲染放入我制作的一些 GUI 中,也在 javafx 中。 How would I do that?我该怎么做?

Basically is there some container I can put a scene into and then put that container into the GUI.基本上有一些容器我可以将场景放入其中,然后将该容器放入 GUI 中。

Sorry if it's a newbie question, I am new to JavaFX对不起,如果这是一个新手问题,我是 JavaFX 的新手

Java 8 has a SubScene , for which some possible uses (from the javadoc) are: Java 8 有一个SubScene ,一些可能的用途(来自 javadoc)是:

The SubScene class is the container for content in a scene graph. SubScene 类是场景图中内容的容器。 SubScene provides separation of different parts of a scene, each of which can be rendered with a different camera, depth buffer, or scene anti-aliasing. SubScene 提供场景不同部分的分离,每个部分都可以使用不同的相机、深度缓冲区或场景抗锯齿进行渲染。 A SubScene is embedded into the main scene or another sub-scene. SubScene 被嵌入到主场景或另一个子场景中。 Possible use cases are:可能的用例是:

  • Mixing 2D and 3D content混合 2D 和 3D 内容
  • Overlay for UI controls UI 控件的叠加
  • Underlay for background背景垫
  • Heads-up display抬头显示器

A SubScene is just a Node, so you can place it in the scene graph of an existing scene wherever you want. SubScene 只是一个节点,因此您可以将其放置在现有场景的场景图中您想要的任何位置。 An example of SubScene usage is in the answer to: How to create custom 3d model in JavaFX 8? SubScene 用法的一个例子是在以下答案中: 如何在 JavaFX 8 中创建自定义 3d 模型?

Generally SubScenes are for mixing 2D and 3D content.通常子场景用于混合 2D 和 3D 内容。 If you are not doing that, then SubScenes probably don't apply to your situation and Uluk's answer will better serve your needs.如果您不这样做,那么 SubScenes 可能不适用于您的情况,而 Uluk 的答案将更好地满足您的需求。

The scene has only a top parent node as a root.场景只有一个顶部父节点作为根。 You can get it and to put into another scene.你可以得到它并放入另一个场景。

((Pane) scene2.getRoot()).getChildren().add(scene1.getRoot());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM