Cannot load image in JavaFX

前端 未结 5 618
离开以前
离开以前 2020-11-28 12:49

I tested this code in order to create dialog with image.

final int xSize = 400;
final int ySize = 280;
final Color backgroundColor = Color.WHITE;
final Strin         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 13:21

    Image img = new Image("file:/logo.png");
    

    or way with path:

    Image img = new Image("file:c:/logo.png");
    

    or

    File f = new File("c:\\logo.png");
    Image img = new Image(f.toURI().toString());
    

    also can use:

    new Image(file:src/logo.png) //root of project
    

提交回复
热议问题