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 8566777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:44:00+00:00 2026-06-11T17:44:00+00:00

Whenever I try to add this image all I get is a blank jFrame.

  • 0

Whenever I try to add this image all I get is a blank jFrame. I am hoping some one can tell me what I am doing wrong. Also I have done a system.out.println on the image and it is getting loaded.

        BufferedImage myPicture = ImageIO.read(getClass().getResourceAsStream("image.jpg"));


        javax.swing.JLabel jLabel2 = new JLabel(new ImageIcon(myPicture));            
        jLabel1.add(jLabel2);
        jLabel1.repaint();
  • 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-06-11T17:44:02+00:00Added an answer on June 11, 2026 at 5:44 pm
    public class LabelJarSample {
    
      public static void main(String args[]) {
        String title = "JLabel Sample";
        JFrame frame = new JFrame(title);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        Container content = frame.getContentPane();
        content.setLayout(new GridLayout(2, 2));
    
        JLabel label1 = new JLabel("Text Label");
        content.add(label1);
    
        Image warnImage = ImageLoader.getImage(LabelJarSample.class, "Warn.gif");
        Icon warnIcon = new ImageIcon(warnImage);
        JLabel label2 = new JLabel(warnIcon);
        content.add(label2);
    
        JLabel label3 = new JLabel("Warning", warnIcon, JLabel.CENTER);
        content.add(label3);
    
        String htmlLabel = "<html><sup>HTML</sup> <sub><em>Label</em></sub><br>"
            + "<font color=\"#FF0080\"><u>Multi-line</u></font>";
        JLabel label4 = new JLabel(htmlLabel);
        content.add(label4);
    
        frame.setSize(300, 200);
        frame.setVisible(true);
      }
    }
    
    
    
    
    final class ImageLoader {
    
      private ImageLoader() {
      }
    
      public static Image getImage(Class relativeClass, String filename) {
        Image returnValue = null;
        InputStream is = relativeClass.getResourceAsStream(filename);
        if (is != null) {
          BufferedInputStream bis = new BufferedInputStream(is);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          try {
            int ch;
            while ((ch = bis.read()) != -1) {
              baos.write(ch);
            }
            returnValue = Toolkit.getDefaultToolkit().createImage(
                baos.toByteArray());
          } catch (IOException exception) {
            System.err.println("Error loading: " + filename);
          }
        }
        return returnValue;
      }
    }
    

    ref:http://www.java2s.com/Code/Java/Swing-JFC/LabelwithImage.htm

    note: also check the image location path is correct

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

Sidebar

Related Questions

Whenever I try installing anything using gem, I get this error - murtaza@murtaza-dev:~$ sudo
Whenever i try to run sqlmetal, i get this: 'sqlmetal' is not recognized as
whenever I try to call my ejb from a client, I get this error
Whenever I try to add this line it crashes my app. Am I not
This is pretty confusing. I'm receiving this error whenever I try to add to
Whenever I try to push in Git I get this: You have not concluded
Several times I get this problem.Whenever I try to center something using margin:0 auto.
Whenever I try to extend the Object prototype, I get an error: Error #1056:
Whenever I try to use apt-get/dpkg, it tries a to install a broken source.
In safari 4 and all explorer browsers, whenever I try to call a function

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.