display ArrayList of images on JPanel

Posted on 2006-04-10
Last Modified: 2010-03-31
Im trying to display all images in directory selected by the user on a JPanel but my images dont get displayed!

public Viewer() {
        super() ;
        fc.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ) ;
        status = fc.showOpenDialog( this ) ;
        if ( status == JFileChooser.APPROVE_OPTION ) {
            directory = fc.getSelectedFile() ;
            d.getDirectoryListing( directory ) ;

        imageStats = "Folder: " + directory.getAbsolutePath() + "\n" ;
        imageStats += "No. of Images: " + d.listOfImages.size() + "\n" ;
        imageStats += "Images:" + "\n" ;

        info.setPreferredSize( new Dimension( 100, 200 ) ) ;
        info.setText( imageStats ) ;
        infoPanel.add( new JScrollPane( info ) ) ;
        infoPanel.add( info ) ;

        columns = d.listOfImages.size() ;
        imagePanel.setLayout( new GridLayout( 1, columns, 5, 5 ) ) ;

        for ( int i = 0 ; i < d.listOfImages.size(); i++ ) {
            imageStats += d.listOfImages.get( i ).toString() + "\n" ;
            imagePanel.add( new JLabel( new ImageIcon( d.listOfImages.get( i ).toString() ) ) ) ;

        this.getContentPane().add( imagePanel, "Center" ) ;
        this.getContentPane().add( infoPanel, "South" ) ;
        this.setVisible( true ) ;
        this.pack() ;
Question by:ellandrd
    LVL 92

    Expert Comment

    check the filenames u are adding:
               System.out.println(d.listOfImages.get( i ).toString() );
               imagePanel.add( new JLabel( new ImageIcon( d.listOfImages.get( i ).toString() ) ) ) ;
    LVL 16

    Author Comment

    filenames are fine.  it was one of the frist things i checked...
    LVL 92

    Accepted Solution

    do the other panels appear?

    after adding them try revalidating the frames content

          ((JComponent)(this.getContentPane()).revalidate() ;
    LVL 16

    Author Comment

    Its working now...

    thank you
    LVL 92

    Expert Comment

    no worries :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now