Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Show output on jTextArea

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    Default Show output on jTextArea

    Hi there, hope you can help me, this is a program made in Netbeans.

    In the attached image, I have a JMenuItem called "Listagem de ficheiros" with an ActionEvent.

    I want to click on it and open a jTextArea that returns the output of next code:

    PHP Code:
    File folder = new File("C:\\Users\\Hugo Monteiro\\Documents\\NetBeansProjects\\FileImporter\\ImagensDB");  
    File[] listOfFiles folder.listFiles();  
             for (
    int i=0i<listOfFiles.lengthi++) {  
                 if (
    listOfFiles[i].isFile()) {  
    jTextArea1.append("File: " +listOfFiles[i].getName().split("-"));  
    1 - i can't make it open a jTextArea to show the output.
    2 - It doesn't split the file name

    normal Output: 001-A Retro Autumn-Garnett Rules-MAI2012-24.45-Landscapes.jpg
    What i want: 001 A Retro Autumn Garnett Rules MAI2012 24.45 Landscapes.jpg

    Thanks in advance.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    Default Re: Show output on jTextArea

    BTW i think the code as to be inside:

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                             
       //código para Output  

    this action performed is from "Listagem de ficheiros", the onde that makes the output

  3. #3
    Join Date
    May 2010
    North Central Illinois
    My Mood
    Thanked 112 Times in 110 Posts

    Default Re: Show output on jTextArea

    File folder = new File("C:\\Users\\Hugo Monteiro\\Documents\\NetBeansProjects\\FileImporte r\\ImagensDB");
    File[] listOfFiles = folder.listFiles();
    for (int i=0; i<listOfFiles.length; i++) {
    if (listOfFiles[i].isFile()) {
    jTextArea1.append("File: " +listOfFiles[i].getName().split("-"));

    While it's allowable, somehow, probably it calls the array's toString, to use the split, which returns an array, you're going to have the word "File: " + a bunch of silly characters that is a String array toString. Probably not what you wanted.

    Also, as far as I know, you can't just "open" a JTextArea itself. I think you need a JFrame or something similar to do that.

    As for the JMenuItem, you could simply use the addActionListener() method.

    split("001-A Retro Autumn-Garnett Rules-MAI2012-24.45-Landscapes.jpg") is returning a String array

    String[] tempArray = split(.......);
    tempArray[0] = "001";
    tempArray[1] = "A Retro Autumn";
    tempArray[2] = "Garnett Rules";
    tempArray[3] = "MAI2012";
    tempArray[4] = "24.45";
    tempArray[5] = "Landscapes.jpg";

  4. #4
    Join Date
    Apr 2012
    Thanked 27 Times in 27 Posts

    Default Re: Show output on jTextArea

    You could instead just use the replaceAll() method. Using the split() method, as stated above, will return an array of strings.

Similar Threads

  1. My bullseye won't show
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 30th, 2012, 06:33 PM
  2. [SOLVED] Why doesn't my Applet show up in my browser?
    By SendBorg in forum Java Applets
    Replies: 3
    Last Post: January 29th, 2012, 07:30 AM
  3. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM
  4. JTextArea output problem
    By grimx in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 8th, 2010, 07:54 PM
  5. [SOLVED] how to print for-loop output to JTextArea
    By voltaire in forum AWT / Java Swing
    Replies: 2
    Last Post: May 13th, 2010, 02:43 PM