Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:51:46+00:00 2026-05-25T15:51:46+00:00

How to display an image to JPanel or to JLabel using the BufferedImage ?

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:51:47+00:00Added an answer on May 25, 2026 at 3:51 pm

    Override paintComponents(g) paintComponent(g) method of JPanel or JLabel and draw image in it. Something like follow:

        JPanel panel = new JPanel(){
            @Override
            public void paintComponent(Graphics g) {
                BufferedImage image = null; // get your buffered image.
                Graphics2D graphics2d = (Graphics2D) g;
                graphics2d.drawImage(image, 0, 0, null);
                super.paintComponents(g);
            }
        };
    

    Same thing for JLabel. Or in another way:

        BufferedImage image = null; // get your buffered image.
        ImageIcon icon = new ImageIcon((Image)image);
        JLabel label = new JLabel();
        label.setIcon(icon);
    

    As you are saying that you are loading image from FileChooser it can be done in following
    way:

        ImageIcon icon = new ImageIcon(
                  fileChooser.getCurrentDirectory().toString()
                  +"/"+fileChooser.getSelectedFile().getName());
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not able to display image using this code. Could any one help
How can I display jpg image which I stored in arraylist in JPanel? Im
I want to display image using base64 encoding in IE using GWT If it
i can't display the image on my aspx view.. i'm using mysql as database
I need to display an image, which I've done without problems before, but today
I want to display the image located in my local drive. I am using
I need to display image with rounded corner with sprite. What is the best
I'd like to display image on top of div using absolute positioning within jQuery's
how to display image view background color with hash values. i need to place
What would be the most appropriate image type to display a jpg image (loaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.