【问题标题】:What is the relationships between Parents, Nodes and Scenes?父母、节点和场景之间的关系是什么?
【发布时间】:2019-07-10 16:14:45
【问题描述】:

我问的是节点、场景和父母之间的关系。我实际上正在学习JavaFX,并且很难在同一帧中更改场景。我为此建立了一种方法,但实际上我不知道它是如何工作的。你能帮我弄清楚吗?

我尝试在 Java 参考、youtube 上以及在 google 上搜索关键字“Scenes Parent”,但没有找到任何对我有帮助的东西。

public class SceneCreator {

  // launching the new scene based on the .fxml file name passed in the argument as a String variable
  // building the scene and setting the value for the instance variable loader
  public static void launchScene (String sceneName) throws IOException {

    // Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    FXMLLoader loader = new FXMLLoader(Main.class.getResource(sceneName));
    Main.setRoot(loader.load());
    Scene scene = new Scene(Main.getRoot());
    Main.getStage().setScene(scene);
    Main.getStage().show();



@FXML
  private void sphereClick() throws IOException{
    System.out.println("Sphere button clicked");
    SceneCreator.launchScene("sphere.fxml");
  }

【问题讨论】:

标签: java javafx nodes parent


【解决方案1】:

欢迎来到 StackOverFlow,请在提问前仔细搜索,但要在此处找到答案:

JavaFX scene 图是顶层的一部分,是开始 构建 JavaFX 应用程序的要点。

它是一个层次结构的节点树,代表应用程序用户界面的所有视觉元素。可以处理输入,可以渲染,参考图片

场景图中的单个元素称为node。每个node 都有一个IDstyle classbounding volume

场景图中的每个节点都有一个single parentzero or more children

请阅读下面这本大约 70 页的书,但它非常有帮助,而且由于您正在学习它,所以没有浪费时间 https://docs.oracle.com/javase/8/javafx/JFXST.pdf

请参阅 stackoverflow 问题,它们真的很有帮助,而且它们针对的是您的问题,例如这个问题:

How to swap screens in a javafx-application in the controller-class?

或者这个

How to switch scenes in JavaFX

【讨论】:

    猜你喜欢
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 2014-08-02
    • 2021-01-04
    相关资源
    最近更新 更多