How can I display a BufferedImage in a JFrame?
You will have to repaint the JFrame
whenever you update the image.
Here is what a simple google on the topic brings up: (I use those tutorials for all my Java coding)
Java Tutorial: Drawing an Image
To build on camickr's solution (for the lazy like me who want quick code to copy/paste) here's a code illustration:
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JLabel(new ImageIcon(img)));
frame.getContentPane().add(new JLabel(new ImageIcon(img2)));
frame.getContentPane().add(new JLabel(new ImageIcon(img3)));
frame.pack();
frame.setVisible(true);
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // if you want the X button to close the app
Just incase life's to short too read the official docs here's a dirty way to get it done multiple times over
private static JFrame frame;
private static JLabel label;
public static void display(BufferedImage image){
if(frame==null){
frame=new JFrame();
frame.setTitle("stained_image");
frame.setSize(image.getWidth(), image.getHeight());
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
label=new JLabel();
label.setIcon(new ImageIcon(image));
frame.getContentPane().add(label,BorderLayout.CENTER);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
}else label.setIcon(new ImageIcon(image));
}