• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

display ArrayList of images on JPanel

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() ;
    }
0
ellandrd
Asked:
ellandrd
  • 3
  • 2
1 Solution
 
objectsCommented:
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() ) ) ) ;
 
0
 
ellandrdAuthor Commented:
filenames are fine.  it was one of the frist things i checked...
0
 
objectsCommented:
do the other panels appear?

after adding them try revalidating the frames content

      ((JComponent)(this.getContentPane()).revalidate() ;
0
 
ellandrdAuthor Commented:
Its working now...

thank you
ellandrd
0
 
objectsCommented:
no worries :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now