DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    2

    Exclamation Opening Text with jFileChooser

    Hello can anyone help me out here i'm new at java programming, i'm using NetBeans3.6.
    Look I want to open a text file using jFileChooser but I don't know how to, i've already opened a text file but without the jFileChooser.

    Here's the code:

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    jTextArea1.setText("");
    String record = null;

    try {

    FileReader fr = new FileReader("/home/gap/Desktop/text.txt");
    BufferedReader br = new BufferedReader(fr);

    record = new String();
    while ((record = br.readLine()) != null) {

    jTextArea1.append(record);
    jTextArea1.append("\n");

    }
    } catch (IOException e) {
    // catch possible io errors from readLine()
    System.out.println("IOException error!");
    e.printStackTrace();
    }
    }

  2. #2
    Join Date
    Sep 2004
    Posts
    223
    here is some code from the java API that may help


    The following code pops up a file chooser for the user's home directory that sees only .jpg and .gif images:
    Code:
        JFileChooser chooser = new JFileChooser();
        // Note: source for ExampleFileFilter can be found in FileChooserDemo,
        // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
        ExampleFileFilter filter = new ExampleFileFilter();
        filter.addExtension("jpg");
        filter.addExtension("gif");
        filter.setDescription("JPG & GIF Images");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(parent);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           System.out.println("You chose to open this file: " +
                chooser.getSelectedFile().getName());
        }
    A kram a day keeps the doctor......guessing

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links