Cannot load image in JavaFX

前端 未结 5 595
离开以前
离开以前 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:20

    Try this:

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

    If no protocol part indicating a URL (as http: or file:) is given, the file is supposed to reside in the default package. If you want it to put in a different package say com.my.images you add this information in a path like manner:

    img = new Image("/com/my/images/logo.png");
    

提交回复
热议问题