View Javadoc

1   package de.matthias_burbach.mosaique.swing;
2   
3   import java.net.URL;
4   
5   import javax.swing.ImageIcon;
6   
7   /***
8    * @author Matthias Burbach
9    */
10  public final class SwingHelper {
11  
12      /***
13       * Private default constructor to enforce static usage of this utility
14       * class.
15       */
16      private SwingHelper() {
17          //nothing to do
18      }
19  
20      /***
21       * @param path The classpath relative path to the image icon.
22       * @param description The dexcription of the image icon.
23       * @return An ImageIcon, or null if the path was invalid.
24       */
25      public static ImageIcon createImageIcon(
26              final String path,
27              final String description) {
28          ImageIcon result = null;
29          URL imageUrl = SwingHelper.class.getResource(path);
30          if (imageUrl != null) {
31              result = new ImageIcon(imageUrl, description);
32          } else {
33              System.err.println("Couldn't find file: " + path);
34              result = null;
35          }
36          return result;
37      }
38  }