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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:17:00+00:00 2026-06-06T22:17:00+00:00

I am trying to load some images in a scrollable pane. But for some

  • 0

I am trying to load some images in a scrollable pane. But for some reason it is not showing up. Here is my piece of code to add Images.

 private JFileChooser fileChooser = new JFileChooser(){
        @Override
        public void approveSelection(){
            File files[] = fileChooser.getSelectedFiles();
            JPanel panel = new JPanel(new GridLayout(files.length, 1));
            for(int lop=0; lop< files.length; lop++){

                BufferedImage image = null;
                try {                
                    image = ImageIO.read(files[lop]);
                } catch (IOException ex) {}
                BufferedImage img = new BufferedImage(100, 100, 1);
                Graphics2D g = img.createGraphics();
                g.drawImage(image, 0, 0, 100, 100, null);
                g.dispose();

                ImageIcon icon = new ImageIcon(img);
                JLabel lable = new JLabel(icon);
                panel.add(lable);    

            }
            jScrollPane1.getViewport().add(panel);    
            super.approveSelection();
        }
    };

Using above fileCHooser, I select some images to load in a vertical scrollPane, somehow, scrollPane horizontal scroller shows up change in length, but there are no contents in the scrollpane. Please check following screenshot. under the title of Shapes: you will see an empty container with extended scrollbars

Screenshot

regards,
Aqif Hamid

  • 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-06T22:17:02+00:00Added an answer on June 6, 2026 at 10:17 pm

    The problem is with this line of code:

    jScrollPane1.getViewport().add(new JFrame().add(panel));
    

    Why do you create a JFrame?

    You should just create the JScrollPane like this:

    jScrollPane = new JScrollPane(panel);
    

    Or set the view of the scrollpane like this:

    jScrollpane.setViewportView(panel);
    

    Also, you should just use panel.add(lable). The GridLayout will put the label at the appropriate location.
    And you should not ignore exceptions. Transform the empty catch block to:

    try {                
        image = ImageIO.read(files[lop]);
    } 
    catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load png images into my game, but for some reason it
I'm trying to load some images using Bitmap.getBitmapResource() , but it takes about 2
In the code below I'm trying to load some images and put them in
I am trying to load an image and add some text to it. my
I am trying to load some XML data into C++ code (classes) using gsoap.
I am trying to generate some HTML code to list some images for a
I'm trying to load profile images (friend images) from Facebook with AS3 but I
Okay, I'm trying to load a 2d array and having some problems. Here's my
I'm trying to iterator over some directories containing approximately 3000 images. I load the
I'm trying to implement uploadify, but for some reason I'm failing at getting the

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.