Skip to main content

Posts

Showing posts from October, 2011

Replace JFrame Icon

By using setIconImage(image) can be used to replace the Java icon. However, you cannot prevent Java icon displaying by using setIconImage(null) since null will be ignored inside the setIconImage function.          // replace the default icon         URL url = getClass().getResource("/tmp/icon.jpg");         ImageIcon imageIcon = new ImageIcon(url);         Image image = imageIcon.getImage();         this.setIconImage(image); If null is returned by getResource(), please make sure that the icon.jpg can be found in the bin folder which stores the compiled java classes. The source code of setIconImage(Image imag) is:   public static ImageIcon loadImageIcon ( String filename ) {     URL url = Config . class . getClassLoader (). getResource ( IMAGE_DIR + filename );     if ( url == null ) {         System . err . println ( "No image for " + filename );         return null ;     }     ImageIcon icon = new ImageIcon ( url );     return

Changing Task Progress By SwingWorker

When SwingWorker is used to report task progress, it should be noted that the propertyChangeEvent won't be invoked if the oldValue is the same as the oldValue. To solve this problem, it is better to reset your progress status to zero or random number before the SwingWorker starts. The setting will force the propertyChangeEvent to be invoked. So your progress status will be updated.