JavaFX 在场景中嵌入场景
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22161586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaFX embed scene in scene
提问by Josh
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. How would I do that?
我有一个应用程序,它使用 javafx 场景来渲染某些东西,我想将该渲染放入我制作的一些 GUI 中,也在 javafx 中。我该怎么做?
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 的新手
采纳答案by Uluk Biy
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());
回答by jewelsea
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 provides separation of different parts of a scene, each of which can be rendered with a different camera, depth buffer, or scene anti-aliasing. A SubScene is embedded into the main scene or another sub-scene. Possible use cases are:
- Mixing 2D and 3D content
- Overlay for UI controls
- Underlay for background
- Heads-up display
SubScene 类是场景图中内容的容器。SubScene 提供场景不同部分的分离,每个部分都可以使用不同的相机、深度缓冲区或场景抗锯齿进行渲染。SubScene 被嵌入到主场景或另一个子场景中。可能的用例是:
- 混合 2D 和 3D 内容
- UI 控件的叠加
- 背景垫
- 抬头显示器
A SubScene is just a Node, so you can place it in the scene graph of an existing scene wherever you want. An example of SubScene usage is in the answer to: How to create custom 3d model in JavaFX 8?
SubScene 只是一个节点,因此您可以将其放置在现有场景的场景图中您想要的任何位置。SubScene 用法的一个例子是在以下答案中:如何在 JavaFX 8 中创建自定义 3d 模型?
Generally SubScenes are for mixing 2D and 3D content. If you are not doing that, then SubScenes probably don't apply to your situation and Uluk's answer will better serve your needs.
通常子场景用于混合 2D 和 3D 内容。如果您不这样做,那么 SubScenes 可能不适用于您的情况,而 Uluk 的答案将更好地满足您的需求。