4

I am making a Summarizer project in NetBeans 6.9.1 in that I have a "Browse" button which should open a open dialog box on JFileChooser. I looked over here: very similar question on stackoverflow

My problem is just the same, I tried setting the current directory which was tried on another similar question on stackoverflow, but even that doesn't work on on my PC.

I still cant figure what the heck is my error. I think it is the same error that the things are not being run on EDT. I am using netbeans, the code is huge. I cant find where to make changes for the EDT thing. So I'll post only relevant part of it. Please see and tell me what do I need to do to solve my problem?

 private void cmdBrowseActionPerformed(java.awt.event.ActionEvent evt) {                                          


        jFileChooser1.setCurrentDirectory(new File("F:/BE-Project/Summarizer"));
        jFileChooser1.setDialogTitle("Open File");
        jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int returnVal = jFileChooser1.showOpenDialog(Summarizer.this);
        if (returnVal== JFileChooser.APPROVE_OPTION) {
            try {

                fin = jFileChooser1.getSelectedFile();
                fileContents = Files.readFromFile(fin,"ISO-8859-1");
                tAreafileContents.setText( fileContents );
                txtInputFile.setText( fin.getAbsolutePath() + " -- " + fin.getName());
                tAreafileContents.setCaretPosition(tAreafileContents.getDocument().getLength());
            }
             catch (Exception e) {
                 System.out.println(e);
             }

        }

        else System.out.println("there is some error");
    }                           

/* netbeans generated code */
 public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Summarizer().setVisible(true);
            }
        });
    }             

Please tell me if any other part of code is needed, and please help. I am scratching my head right now.

Community
  • 1
  • 1
Navin Israni
  • 1,327
  • 3
  • 15
  • 27
  • 3
    "please tell me if any other part of code is needed.." For better help sooner, post an SSCCE (http://pscode.org/sscce.html). An SSCCE might tell me & others in what *security environment* this code is being called, among other things. Note that the 'else' will never be reached if there is a security sand-box in effect. – Andrew Thompson Mar 19 '11 at 07:35
  • @andrew thanks for caring to at least reply..i would request you to not add to my complications...i am already in a fix coz of jfilechoser freezing my application...u r only adding more complexities to it my mentioning things like SSCCE..i dont need things now – Navin Israni Mar 20 '11 at 15:30
  • @andrew regarding my application, what other info u need? it just a simple button in netbeans..buy "other part of code" i meant any part of the huge netbeans auto-generated code that u might need to try to fix my problem..i think my problem seem to be that jfilechooser takes too long to access the file system..which is why it freezes my application..but i cant seem to figure out why is it taking so long that its freezing my app..dats really the problem – Navin Israni Mar 20 '11 at 15:33

2 Answers2

1

I would suggest that your issue is in reading the File from disk in the EDT.

 //this should be in a worker thread
 fileContents = Files.readFromFile(fin,"ISO-8859-1");

 //this then gets dumped back on the EDT
 tAreafileContents.setText( fileContents );
 txtInputFile.setText( fin.getAbsolutePath() + " -- " + fin.getName());
 tAreafileContents.setCaretPosition(tAreafileContents.getDocument().getLength());
akf
  • 38,619
  • 8
  • 86
  • 96
  • thanks akf for replying...this was my final year engg project..i have stopped working on it more than 2 months ago..i didn't use jFileChooser since it wasnt working..although i don't remember what i used (i haven't touched it since more than 2 months)..but still thanks for replying..i'll surely try it the next time lay my hands back on it.. – Navin Israni Jul 20 '11 at 07:11
0

Are you sure is a JFileChooser problem only? Is your F: unit a hard drive, a network share, a usb drive? If is not, could you try changing the unit to a hard drive? Run these test within netbeans and on command line, reading files on F: and some other unit different to F

import java.io.*;

public class FileSize 
{
    public static void main(String [] args)
    {
        //String fileName = "F:/BE-Project/Summarizer/someFile.txt");
        String fileName = "FileSize.java";
        long size = new File(fileName).length();
        System.out.println("size: " + size);
    }

}
Awi
  • 285
  • 1
  • 3
  • 12
  • thanks awi for replying...this was my final year engg project..i have stopped working on it more than 2 months ago..i didn't use jFileChooser since it wasnt working..although i don't remember what i used (i haven't touched it since more than 2 months)..but still thanks for replying..i'll surely try it the next time lay my hands back on it.. – – Navin Israni Jul 20 '11 at 07:11