我一直想弄清楚如何在舞台标题旁边放置舞台图标。我无法为此制定解决方案。如何让我的Icon位于我的标题旁边?
stage.getIcons().add(new Image(""));
stage.setTitle("");
stage.setScene(scene);
stage.show();
答案 0 :(得分:0)
我没有50个声誉来添加评论,但您并没有真正解释当前代码的问题。这些是正确的方法,但也许你的文件位置不对吗?请参阅以下示例:
public class MainApp extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml"));
Scene scene = new Scene(root);
stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/images/so-icon.png")));
stage.setTitle("Icon Example");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}