-1

Im new to JavaFX and im trying to set the icon of the window but I keep getting a Invalid URL error and im not sure why. The image is placed in the application folder so it should be able to locate it no problem so im not sure why it is unable to locate it.

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


public class Main extends Application {
    @Override
    public void start(Stage stage) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
            Scene scene = new Scene(root);
            
            Image icon = new Image("icon.png");
            stage.getIcons().add(icon);
            stage.setTitle("Double Tap UI");
            stage.setScene(scene);
            stage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}

0 Answers0