w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Java Swing: Runnable JAR file does not work when including images

POSSIBILITY 3 TO HANDLE IMAGE :

You can check that resource that you are fetching is exist or not. It resource not found then you can create JLabel with alternative text also...

JLabel label1 ;
URL imageUrl =
IconTest.class.getClassLoader().getResource("strawberry.jpg");
if ( imageUrl != null ) {
    label1 = new JLabel(new ImageIcon(imageUrl));
} else {
    label1 = new JLabel("Alternative text");
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.