Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Bartman

Thread: Detect change to file(s) using getFileSystemView

  1. #1
    Bartman is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Detect change to file(s) using getFileSystemView

    This one is driving me crazy. I have done this using 'C', so I know it is possible.

    My java app lays out graphical 'tiles' in a grid. In order to help the artist view how updates to a tile looks next to adjacent tiles, I added a 'reload tiles' option. This is intended to load the images and it does not work. It does detect additions/subtractions to the tiles directory, but doesn't load tile changes.

    Here is the code in question.
    Java Code:
        private void populateTileChooserPanel()
        {
            m_tileChooserPanel.removeAll();
            m_tileChooserPanel.setVisible(false);
            final int gap = 2;
    
            // first we must find the files in the tiles directory
            FileSystemView fsv = FileSystemView.getFileSystemView();
            File [] theFiles = fsv.getFiles(new File("tiles"),true);
            int numFiles = theFiles.length;
    
            m_theTileChooserButtons = new TileChooserButton[numFiles];
            MyImageIcon[] theImages = new MyImageIcon[numFiles];
            MyImageIcon    tempImage;
            String[] filenames = new String[numFiles];// path excluded
            String[] goodFilenames = new String[numFiles];
    
            for (int i=0 ;i<numFiles; i++)
            {
                filenames[i] = theFiles[i].getName();
                tempImage = new MyImageIcon(theFiles[i].getPath());
    ---- unrelated code snipped -----
                if (!wrongSize)
                {
                    goodFilenames[numGoodFiles] = filenames[i];
                    theImages[numGoodFiles++]   = tempImage;
                }
            }
            // now build the panel
            m_tileChooserPanel.setLayout(new GridLayout(numGoodFiles, 1, gap, gap));
            m_tileChooserPanel.add(tileChooserHelp);    
    
            for (int i=0; i<numGoodFiles; i++)
            {
                m_theTileChooserButtons[i]= new TileChooserButton(goodFilenames[i], theImages[i], this);
                m_tileChooserPanel.add(m_theTileChooserButtons[i]);
            }
            m_tileChooserPanel.setVisible(true);
        }
    Any help is appreciated.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Detect change to file(s) using getFileSystemView

    The ImageIcon constructor that takes a String parameter loads the image using java.awt.Toolkit, and Toolkiit caches images. To force a reload you need to flush() the ImageIcon's Image.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Detect change to file(s) using getFileSystemView

    Also, there's no need to use FileSystemView. The File API is adequate for what you are doing.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Bartman is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Re: Detect change to file(s) using getFileSystemView

    Thank you. I knew there had to be a flush somewhere. That fixed it.

    P.S. Not sure why I was stuck on FileSystemView, but you are correct that the File class works also.
    DarrylBurke likes this.

Similar Threads

  1. InputStream is unable to detect file
    By HardRock in forum Eclipse
    Replies: 2
    Last Post: 06-24-2012, 11:38 AM
  2. Easiest way to detect beeps in audio file
    By bill17 in forum New To Java
    Replies: 0
    Last Post: 11-26-2011, 04:46 PM
  3. How can I detect the end of a line in a file ?
    By ze snow in forum New To Java
    Replies: 5
    Last Post: 02-17-2010, 10:57 AM
  4. Detect new file entry
    By rdemon in forum Advanced Java
    Replies: 4
    Last Post: 01-08-2010, 02:24 AM
  5. Replies: 0
    Last Post: 01-20-2008, 06:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •