gpt4 book ai didi

javafx - JavaFX窗口setTitle

转载 作者:行者123 更新时间:2023-12-04 18:05:34 24 4
gpt4 key购买 nike

我有一个主要的类(class),如下所示:

public class Window extends Application {


@Override
public void start(Stage foablak) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Foablak.fxml"));
Scene scene = new Scene(root);

foablak.setScene(scene);
foablak.setWidth(900);
foablak.setHeight(700);
foablak.setResizable(false);
foablak.setTitle("Window");

foablak.show();
}

public static void main(String[] args) {
launch(args);
}

}

如何在不关闭窗口并打开新窗口的情况下从另一个.java类更新Title的标题?

最佳答案

仅出于公开的目的,使用static公开属性可能被认为是错误的设计。您可以通过不同的方法来实现相同的目的,例如,从设置阶段标题的Window类中公开一个方法。

public class Window extends Application {

private Stage stage;

@Override
public void start(Stage foablak) throws Exception {
stage = foablak;
Parent root = FXMLLoader.load(getClass().getResource("Foablak.fxml"));
Scene scene = new Scene(root);

foablak.setScene(scene);
foablak.setWidth(900);
foablak.setHeight(700);
foablak.setResizable(false);
foablak.setTitle("Window");

foablak.show();
}

public static void main(String[] args) {
launch(args);
}

public void setStageTitle(String newTitle) {
stage.setTitle(newTitle);
}
}

关于javafx - JavaFX窗口setTitle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29055792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com