Java GIF animation not repainting correctly

Okay, so after much mucking about, I was able to, finally, change the disposal method for the frame to restoreToBackgroundColor. Basically, what this means is that the animation is not an incremental change, but a complete frame replacement… import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JFrame; import … Read more

How to set Icon to a JLabel from an image from a folder?

This is my directory structure : packageexample | ——————————————- | | | build(folder) src(folder) manifest.txt | | swing(package) ComboExample.java | imagetest(subpackage) | ComboExample.class + related .class files This is the content of the ComboExample.java file : package swing.imagetest; import java.awt.*; import java.awt.event.*; import java.net.*; import javax.swing.*;      public class ComboExample { private String[] data … Read more

JLabel images array

For comparison, I’ve re-factored @HFOE’s example so that Ground implements Icon and indexes the array returned by values(). As value is an implementation detail, int[][] MAP could instead be Ground[][] MAP. Update: This variation illustrates Ground[][] MAP and adds TexturePaint. import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.TexturePaint; import java.awt.geom.Rectangle2D; import … Read more

Java in Eclipse: Where do I put files on the filesystem that I want to load using getResource? (e.g. images for an ImageIcon)

For Eclipse, typically all you need to do is set up a folder somewhere within your source code directory. For instance, if the directory containing your source is /src then you can create a /src/resources folder to place your images/files in. Then, within your class you do a getResource(“/resources/image.png”) to retrieve it. You can also … Read more

Java Swing: Displaying images from within a Jar

To create an ImageIcon from an image file within the same jars your code is loaded: new javax.swing.ImageIcon(getClass().getResource(“myimage.jpeg”)) Class.getResource returns a URL of a resource (or null!). ImageIcon has a constructors that load from a URL. To construct a URL for a resource in a jar not on your “classpath”, see the documentation for java.net.JarURLConnection.