Sistema de blogs Diarium
Universidad de Salamanca
Pablo Gallardo's Blog
My professional web log about IT, Cybersecurity & Project Management

How to display an image on Java Swing

Images can be displayed in Java Swing using object JLabel.

This is the partial code:

JLabel label = new JLabel();
try {
BufferedImage img = File(IMG_FILES_PATH + IMG_FILENAME));
ImageIcon icon = new ImageIcon(img);
} catch (IOException ex) {
Logger.getLogger(SwingGUIMainScreen.class.getName()).log(Level.SEVERE, null, ex);

If I need the image to have an specific size, what I do is resizing the BufferedImage object. Read this other post to find more about it.


About pmgallardo

I studied Computer Science at University of Salamanca. Since then, I have been working first as developer and then as SAP consutant. This blog is about problems I dealt when using computers, and more important, the solutions I found. Whenever I am on an issue and suddenlly I have a flash that leads me to a solution, I document my discoveries in a post.

, , , ,

No comments yet.

Leave a Reply


Política de privacidad
Studii Salmantini. Campus de excelencia internacional