Image previewer for Java

At the moment I’m processing images in a CLI-Java-application. For debugging puposes it’s sometimes nice to have a way to display Image objects, like some kind of visual replacement for System.out.println(xyz).

This small method might be helpful in such cases:

public static void preview(Image image) {
	JFrame frame = new JFrame();
	JLabel label = new JLabel(new ImageIcon(image));
	frame.getContentPane().add(label, BorderLayout.CENTER);
	frame.pack();
	frame.setVisible(true);
}

Leave a Reply