How to display an image to JPanel or to JLabel using the BufferedImage?
I load an Image using FileChooser and I need to display what I’ve loaded.
I don’t extend my class to any container.
How to display an image to JPanel or to JLabel using the BufferedImage ?
Share
Override
paintComponents(g)paintComponent(g)method of JPanel or JLabel and draw image in it. Something like follow:Same thing for JLabel. Or in another way:
As you are saying that you are loading image from
FileChooserit can be done in followingway:
Now you can use ImageIcon in JLabel or add it in JPanel.
Above code is sample code and not tested so not necessary to run without error. You might need to change it as per your need.