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

  • Home
  • SEARCH
  • 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 7581651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:14:54+00:00 2026-05-30T18:14:54+00:00

Here is my code. It does not show images in the frame and instead

  • 0

Here is my code. It does not show images in the frame and instead shows some text. would anybody please suggest me that what change I should make in the code so that it allows me to show the images in a frame?

import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class ListView {


public static void main(String[] args) throws IOException {
    JFrame frame=new JFrame();
    frame.setSize(500,500);
    JLabel lbl[] = new JLabel[10];
    DefaultListModel listModel;
     ImageIcon[] b = new   ImageIcon[10];
    //JList lsm=new JList();
    listModel = new DefaultListModel();
     File folder = new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures");
     File[] listOfFiles = folder.listFiles();
      JLabel[] lb=new JLabel[15];
    for (int i = 0; i < listOfFiles.length; i++) 
    {
          System.out.println("chek panth"+listOfFiles[i].getName().toString());
  //      b[i] = ImageIO.read(new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/" + listOfFiles[i].getName().toString()));
         b[i] = new ImageIcon("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/" + listOfFiles[i].getName().toString());
         lb[i]=new JLabel(b[i]);
         listModel.add(i, lb[i]);

    }
    JList lsm=new JList(listModel);

    Component add = frame.add(new JScrollPane(lsm));

    frame.setVisible(true);

}


}
  • 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-30T18:14:55+00:00Added an answer on May 30, 2026 at 6:14 pm

    Note that I would not design the code this way, but I wanted to keep it as close to the original as practical, while making it work to display a list of images on a Windows based box.

    ListView

    import java.awt.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    
    public class ListView {
    
        public static void main(String[] args) throws IOException {
            String path = "C:/Documents and Settings/All Users/Documents/" +
                "My Pictures/Sample Pictures";
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
            File folder = new File(path);
            File[] listOfFiles = folder.listFiles();
            DefaultListModel listModel = new DefaultListModel();
            int count = 0;
            for (int i = 0; i < listOfFiles.length; i++)
            {
                System.out.println("check path"+listOfFiles[i]);
                String name = listOfFiles[i].toString();
                // load only JPEGs
                if ( name.endsWith("jpg") ) {
                    ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i]));
                    listModel.add(count++, ii);
                }
            }
            JList lsm=new JList(listModel);
            lsm.setVisibleRowCount(1);
    
            frame.add(new JScrollPane(lsm));
    
            frame.pack();
            frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code here that does not work despite me using
here is my code it shares the folder but that does not work correctly
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
Here's the code, I don't quite understand, how does it work. Could anyone tell,
I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685 However, it does
I've seen other questions here about PNS, in terms of code, but how does
Not sure how to explain this, so I'll first post some code and then
in a database there are some images [of unknown number], i need to show
I like to change some canvas image (hat and jacket) here is the code
Ok the error is showing up somewhere in this here code if($error==false) { $query

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.