JavaFX在一个场景中有多个窗格吗? [英] JavaFX Have multiple Panes in one scene?
问题描述
我正在尝试创建一个应用程序,该应用程序的顶部将有一个日期(总是自动居中),而底部则没有任何方向的内容.
我认为最好的方法是:
Pane normalLayout = new Pane();
StackPane centeredLayout = new Stackpane();
Label centeredText = new Label("I want this text centered!");
Button unorganizedButton = new Button("Press me");
centeredLayout.getChildren().add(centeredText);
normalLayout.getChildren().add(unorganizedButton);
但是我不能做类似的事情:
Scene myScene = new Scene(centeredLayout, normalLayout, 500, 500);
Window myWindow = new Window();
myWindow.setScene(myScene);
myWindow.show();
那怎么办呢?同一场景中如何存在多个窗格?
场景本身只能具有一个 root 窗格. 因此,如果要在场景"中有2个窗格,则需要3个.
Scene
|
V
Root Pane (Vbox for example)
| |
V V
Pane1 Pane2
在您的代码中,它可能看起来像这样:
StackPane rootPane = new StackPane();
Scene scene = new Scene(rootPane,...);
Pane pane1 = new Pane();
Pane pane2 = new Pane();
rootPane.getChildren().addAll(pane1,pane2);
根据应用程序的布局方式,必须选择正确的Pane实现.
作为熟悉所有布局容器的一些提示,请尝试使用SceneBuilder应用程序. http://gluonhq.com/open-source/scene-builder/ >
也许此链接将帮助您了解JavaFX中的布局工作方式: http://docs.oracle.com/javafx/2/scenegraph/jfxpub -scenegraph.htm https://docs.oracle.com/javafx/2/layout/builtin_layouts.htm
I am trying to make an application which will have a date at the top (always automatically centered) and content at the bottom which is not going to be aligned to any direction.
I figured the best way to do this would be to have:
Pane normalLayout = new Pane();
StackPane centeredLayout = new Stackpane();
Label centeredText = new Label("I want this text centered!");
Button unorganizedButton = new Button("Press me");
centeredLayout.getChildren().add(centeredText);
normalLayout.getChildren().add(unorganizedButton);
But then I can't do something like:
Scene myScene = new Scene(centeredLayout, normalLayout, 500, 500);
Window myWindow = new Window();
myWindow.setScene(myScene);
myWindow.show();
So how can this be done? How can multiple panes exist on the same scene?
The Scene it self can only have one root Pane. So if you want 2 panes in the Scene you need 3.
Scene
|
V
Root Pane (Vbox for example)
| |
V V
Pane1 Pane2
In your code this can look like this:
StackPane rootPane = new StackPane();
Scene scene = new Scene(rootPane,...);
Pane pane1 = new Pane();
Pane pane2 = new Pane();
rootPane.getChildren().addAll(pane1,pane2);
Depending on how your Application should be layouted you have to choose the right Pane implementations.
As a little Tip to get familiar whit all the Layout Containers try the SceneBuilder Application. http://gluonhq.com/open-source/scene-builder/
Maybe this link will help you understanding how layouting works in JavaFX: http://docs.oracle.com/javafx/2/scenegraph/jfxpub-scenegraph.htm https://docs.oracle.com/javafx/2/layout/builtin_layouts.htm
这篇关于JavaFX在一个场景中有多个窗格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!