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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:10:40+00:00 2026-06-02T00:10:40+00:00

My application is basically a photo browser . My approach (don’t judge me, I

  • 0

My application is basically a photo browser. My approach (don’t judge me, I am new to java) was to have an ArrayList filled with BufferedImages and then add the images to the JList(to the left).

This is how I get an image :

private void getFullImage() {

        BufferedImage im = null;        


        ImageReader imageReader = null;
            try {
                System.out.println("Loading "+original+"...");
                String suffix = Utils.getFileExt(original.getName(), "jpg");
                @SuppressWarnings("rawtypes")
                Iterator readers = ImageIO.getImageReadersBySuffix(suffix);
                imageReader = (ImageReader)readers.next();
                imageReader.setInput(new FileImageInputStream(original));
                im = imageReader.read(0);
                imageReader.dispose();
            } catch (Exception e)
            {
                e.printStackTrace();
            }

        this.img = im;
    }

and then, after I fetched all the data, I would add the images to my JList :

   Vector vector = new Vector();
   JPanel container = null;
   PhotoPanel pp = null;
   Photo p = null;
   for(int i=0;i<files.length;i++)
   {
        p = new Photo(files[i]);
        pp = new PhotoPanel(p);
        container = new JPanel(new BorderLayout());
        container.add(pp,BorderLayout.CENTER);
                                       container.setBorder(BorderFactory.createTitledBorder(p.getTitle()));
                                vector.addElement(container);
  }
   plist.setListData(vector);

If I have for example 10 files, the app works pretty well. The problem is when I have a lot more images to show. Then I would get an exception : Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space. So, I know my approach is a very poor one, and I am wondering how should I take and store all the images and have them to be displayed in the JList. Maybe using the cache memory? I read something about SoftReference but I don’t really know how to use it. Thanks.

  • 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-02T00:10:42+00:00Added an answer on June 2, 2026 at 12:10 am

    There are two main possible causes for the problem:


    The first, and which I’m posting more as a warning than as an actual cause in your case, is that an excessive amount of data is being printed on the console with the System.out.println().

    I am unsure if it only occurs with NetBeans or all Development tools. But either way, it requires a truly absurd amount of printing for it to be triggered, and i doubt you have that many files loading.

    Anyways, if your intent with the System.out.println("Loading "+original+"..."); line is for a permanent/production logging, rather than something you’ve put on code just temporarily for development/debug purposes, then you are better off with a proper Logger. You can read a TL;DR version of instructions in this SO answer, and you can read further, including the official documentation, through the links provided there.


    The other cause, which is quite certainly your’s, is that you are having too much data loaded at the same time. The solutions are to either:

    1. Scale down the images (make thumbnails), and only show the full-size version for the selected image. Please note tough, that this is a fast solution method, and is not recommended! As it might still be too much for the system to withstand.
    2. Only have the images present at visible portion of the interface loaded (or the thumbnails of said images, for a combined, best solution), and load new images (and unload the others), as the interface is navigated.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write cross platform application (basically CRUD). Is usage of Java Swing
I have an iPhone application which basically is getting information from an API (in
I have a simple application which basically consists of a line of buttons and
I am trying to design a new application which basically aims at providing biometric
I have a Android Application which is basically uses WebView for all interaction.. How
We have a staging version of our web application (it is basically a subversion
We currently have a Live ASP.NET application (Basically a CMS) running on our IIS7
I have a WPF app with a listview control. The application basically loads a
All, I have written a PhoneBook application in Java that is command line based.
I have a WPF Application basically the exe is a loader for the application

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.