2018년 3월 10일 토요일

[JavaFX] How to change main windows icon and title (JavaFX에서 윈도우 아이콘 및 제목 바꾸기)

Insert below source code in the start() function of main class.
메인 클래스의 start() 함수내에 다음 코드를 삽입한다.
stage.getIcons().add(new Image(BloggerPostSnippet.class.getResourceAsStream("android.png")));
stage.setTitle("Blogger Post Snippet");

FullSource (line 13~14)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package bloggerpostsnippet;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

public class BloggerPostSnippet extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        stage.getIcons().add(new Image(BloggerPostSnippet.class.getResourceAsStream("android.png")));
        stage.setTitle("Blogger Post Snippet");
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);       
        stage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

Result:
  

Project Folder:


댓글 없음:

댓글 쓰기