Using JTextArea - How do I clear it?

Hi all.
I have written a GUI program which transfers data from a method to a JTextArea/JScrollPane upon a button ActionEvent.
When I press the "Next Record" button I want to be able to clear the previous details held in this JTextArea before I print the new ones in it. The Same for going backwards through an array. Does anybody know how to do this?
Currently I am using the append method to add the returned String to my JTextArea. I have also tried using a replaceRange(String, int, int) method to clear the box before printing new details, but this isn't working properly as each Record in the array contains a different String length, so I can not enter the int values for each specific object.
Below is the code for the application, and I've highlighted where I have used the methods to add a String to the JTextArea. I'm declaring the class for the action event within creating the actionListener, but can seperate it out if people need to see it more clearly.
RECORDING CLASS ----------
package RecordingManagerGUI;
public class Recording
private String title, artist, genre;
     public Recording (String theTitle, String theArtist, String theGenre)
          title = theTitle;
          artist = theArtist;
          genre = theGenre;
        public String getAlbum()
            return title;
        public String getArtist()
            return artist;
        public String getGenre()
            return genre;
     public String toString()
          String s = "Title: " + title + "\nArtist: " + artist + "\nGenre: " + genre + "\n\n";
          return s;
}MANAGER CLASS ---------------
package RecordingManagerGUI;
import java.util.*;
public class Manager
private Recording[] theRecordings;
private int numRecordings, maxRecordings, age;
private String managerName;
//Extending the Manager Class Instance Variables
private int current = 0;
private String record;
     public Manager (String theName, int theAge, int max)
          managerName = theName;
                age = theAge;
          maxRecordings = max;
          numRecordings = 0;
          theRecordings = new Recording[maxRecordings];
     public boolean addRecording (Recording newRecording)
          if (numRecordings == maxRecordings)
               System.out.println("The store is full");
               return false;
          else
               theRecordings[numRecordings] = newRecording;
               numRecordings++;
               return true;
        public int nextRecording ()
            if(current < numRecordings)
                current += 1;
            else
                record = "You have reached the end of the Records"; //initialise the string if no records
            return current;
        public int previousRecording()
            if(current > 1)
                current -= 1;
            else
                record = "You have reached the start of the Records"; //initialise the string if no records
            return current;
        public String displayCurrent()
            String displayRec = "";
            displayRec += theRecordings[current-1];
            return displayRec;
     public void displayDetails()
          System.out.println("Manager Name: " + managerName + ", " + age);
     //public void displayRecordings()
     //     System.out.println("\nThe Recordings: ");
     //     for (int i = 0; i < numRecordings; ++i)
     //          System.out.println(theRecordings);
}RecordingManagerGUI CLASS ----------/*
*Need to add a Label which tells me when I have reached the end of the Records
package RecordingManagerGUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RecordingManagerGUI extends JFrame {
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
JButton nextRecord;
JButton previousRecord;
JLabel recordLabel;
JTextArea displayRecord;
Manager theManager;
public RecordingManagerGUI() {
//Create and set up the window.
super("Recording Manager Application");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Recording FooFighters = new Recording("The Colour and the Shape", "Foo Fighters", "Rock");
Recording BlindMelon = new Recording("Blind Melon", "Blind Melon", "Alternative Rock");
Recording JoeSatriani = new Recording("The Extremist", "Joe Satriani", "Instrumental Rock");
Recording PercySledge = new Recording("When a Man Loves a Woman", "Percy Sledge", "Soul");
Recording JustinTimberlake = new Recording("Justified", "Justin Timberlake", "Pop");
Recording BeyonceKnowles = new Recording("Dangerously in Love", "Beyonce Knowles", "R'n'B");
Recording TupacShakur = new Recording("2Pacalypse Now", "Tupac Shakur", "Hip Hop");
theManager = new Manager("Cathy", 42, 7);
theManager.addRecording(FooFighters);
theManager.addRecording(BlindMelon);
theManager.addRecording(JoeSatriani);
theManager.addRecording(PercySledge);
theManager.addRecording(JustinTimberlake);
theManager.addRecording(BeyonceKnowles);
theManager.addRecording(TupacShakur);
displayRecord = new JTextArea(10, 30);
displayRecord.setEditable(false);
JScrollPane recordScroll = new JScrollPane(displayRecord);
recordLabel = new JLabel("Record Details");
nextRecord = new JButton("Next Record");
nextRecord.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){theManager.nextRecording();displayRecord.append(theManager.displayCurrent());displayRecord.replaceRange(theManager.displayCurrent(), 0, 30);}}); //ADDING STRING TO JTEXTAREA
previousRecord = new JButton("Previous Record");
previousRecord.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){theManager.previousRecording();displayRecord.replaceRange(theManager.displayCurrent(), 0, 30);}}); //ADDING STRING TO JTEXTAREA
getContentPane().setLayout(new FlowLayout());
getContentPane().add(recordLabel);
getContentPane().add(recordScroll);
getContentPane().add(nextRecord);
getContentPane().add(previousRecord);
//Display the window.
pack();
setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
new RecordingManagerGUI();
}Would appreciate any help thanks. I'm not sure if I just need to create a new instance of the JTextArea upon the event which would hold the String information. If so I'm not really sure how to do this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

I don't know, the Swing experts are in the Swing forum. but setText() is defined in TextComponent, which a JTextArea is.

Similar Messages

  • Bought used Macbook, how do I clear it to make it MINE.

    I bought a used macbook, how do I clear it and make it mine.  It has snow leopard on it and I have disk for Snow Leopard cause I have a MacBook Pro.
    I would like to erase everything and start new with it.  It has a 80gb hard drive and I want to put only what I want on it.
    Where can I get instructions on doing it?  Also I would like to have a larger HD on it.  Is it possible for me to replace the one it has?  Also the battery is totaled and the machine has to be pluged in all the time.  I am going to order another battery.
    Any help I can get WOULD BE GREATLY appreciated.
    Thanks
    ALR1

    Please note that a gray label installer for another model is machine specific. It may not work on this machine. Better to use the retail Snow Leopard DVD.
    You can purchase Snow Leopard through the Apple Store: Mac OS X 10.6 Snow Leopard - Apple Store (U.S.). The price is $19.99 plus tax. You will be sent physical media by mail after placing your order.
    Clean Install of Snow Leopard
    Be sure to make a backup first because the following procedure will erase
    the drive and everything on it.
         1. Boot the computer using the Snow Leopard Installer Disc or the Disc 1 that came
             with your computer.  Insert the disc into the optical drive and restart the computer.
             After the chime press and hold down the  "C" key.  Release the key when you see
             a small spinning gear appear below the dark gray Apple logo.
         2. After the installer loads select your language and click on the Continue
             button. When the menu bar appears select Disk Utility from the Utilities menu.
             After DU loads select the hard drive entry from the left side list (mfgr.'s ID and drive
             size.)  Click on the Partition tab in the DU main window.  Set the number of
             partitions to one (1) from the Partitions drop down menu, click on Options button
             and select GUID, click on OK, then set the format type to MacOS Extended
             (Journaled, if supported), then click on the Apply button.
         3. When the formatting has completed quit DU and return to the installer.  Proceed
             with the OS X installation and follow the directions included with the installer.
         4. When the installation has completed your computer will Restart into the Setup
             Assistant. Be sure you configure your initial admin account with the exact same
             username and password that you used on your old drive. After you finish Setup
             Assistant will complete the installation after which you will be running a fresh
             install of OS X.  You can now begin the update process by opening Software
             Update and installing all recommended updates to bring your installation current.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.

  • I just purchased a used imac how do I clear then reinstall new os

    I just purchased a used imac how do I clear then reinstall new os

    Klaus1 is perhaps too brief if you have not done that before:
    1. Put first DVD in the optical drive
    2. restart and, immediately after chime, press C—this forces boot from CD/DVD, wait until you see Apple logo, then release C key
    3. wait until you see the list of install languages, English is default, click ahead and now
    4. Go up and choose Utilities, open Disk Utility, and choose to Erase/Format disk, as you wish
    5. Close Disk Utilities and you will be redirected to installation proper
    6. Go ahead according to what you see on the screen
    If you do not have the two DVDs of any mac (bar the very recent ones, with Lion preinstalled), you must get a retail one, perhaps SL would be best or Lion, flash drive version directly. Booting from retail DVD is identical; for flash boot, press Option key after chime, then choose the USB flash disk, you will see it on the screen after several seconds.
    The process is simple and logical, do not be afraid, you just need the install DVD or, beginning with Lion, Lion flash drive version. You may of course download the App Store version of Lion, which is at half price approx., but you need another mac to move it to another disk / flash drive in order to install it or do that before you erase the disk which, I understand, has a running system on it.

  • I just got this used phone how do I clear this old fire fox account?

    I cant figure this out please help

    * Open the Android Settings
    * Select Apps
    * Select Firefox
    * Tap the clear data button
    This will clear all the Firefox for Android data stored on the phone and leave you with a clean install. This includes bookmarks, history, passwords and the Firefox account.

  • How do i clear email address memory

    suggestions for email contact include contacts that are no longer in use.  how do i clear those suggestions?  thanks.

    Only by restoring your phone as a new device in iTunes, or if you know how to edit SQLite databases, you could edit your iPhone backup & then restore your phone from that edited backup. Otherwise, you live with it. The data will be overwritten as you use your phone.
    There is no way to edit this database directly on the phone itself.

  • HT201269 I have a old phone i want to give to my daughter.  how do i clear the contacts and emails?

    I have an old phone that i want my daughter to use.  how can i clear the contacts text messages and add music

    Before Selling or giving away an iOS Device...
    If desired, move photos/videos off the Camera Roll: http://support.apple.com/kb/HT4083
    If desired, backup the device to iTunes or iCloud: http://support.apple.com/kb/ht1766
    Then, on the device...
    Settings > Messages > iMessage > Off
    Settings > FaceTime > Off
    Settings > iCloud > (scroll down) Delete Accout (this only unregisters and deletes it off the device)
    Settings > iTunes & App stores.  Tap the AppleID and sign out.
    Settings > General > Reset > Erase All Content and Settings
    Unregister your device at https://supportprofile.apple.com
    More Info... http://support.apple.com/kb/HT5661

  • TS3297 iTunes puts up a message "The item you've requested is not currently available in the Hong Kong Store." I had not requested anything from the HK store at that point, and I have never used any store other than the HK one. How I can clear that messag

    I've been running iTunes on WinXP for years with few problems.  I have all my iTunes files on an external USB drive. I just bought a new PC running Win7, 64-bit.
    I connected the external USB drive to the new PC and installed 64-bit iTunes on it. When iTunes started up, I pointed it at the iTunes directory in the external drive, using Edit > Preferences > Advanced > iTunes Media Folder Location. It showed a progress bar that it was updating the iTunes Library. I signed in and authorized the new machine. I have one spare authorization.
    Then iTunes put up a message "The item you've requested is not currently available in the Hong Kong Store." I had not requested anything from the HK store at that point, and I have never used any store other than the HK one.
    When I click OK, the iTunes Store page remains blank, apart from saying "iTunes Store" in the middle of the page.
    I went to "View My Account" and pressed the Reset button to "Reset all warnings for buying and downloading items", but that doesn’t fix this particular warning. I also tried Edit > Preferences > Advanced > Reset Warnings and Rest Cache.
    But still, every time I click the “App Store” button in the iTunes Store window, the message appears. If I click the Books, Podcasts or iTunesU buttons, these display normally.  So I’m stuck with being unable to purchase apps, other than through my iPad and iPhone.
    If I move the external drive back to the XP machine, the same thing happens.  If I go to another PC - a notebook running Vista - everything is normal.
    Any idea how I can clear that message?
    Thanks for any help you can offer.

    Further info on my question above.
    I have tried re-validating my credit card, which apparently fixed it for some. 
    I have also tried uninstalling, re-downloading and installing again.
    Neither of these steps fixed the problem.

  • I deleted all my photos and videos and then delete the deleted files but the photo app is still taking up 12 GB of space and I have no room for new stuff.  How can I clear the memory space used by my deleted videos and photos?

    I deleted all my photos and videos and then delete the deleted files but the photo app is still taking up 12 GB of space and I have no room for new stuff.  How can I clear the memory space used by my deleted videos and photos?  I don't know why the photos are still taking up space and if I will have to reset my phone to get rid of the problem.

    Hey there TowneJ,
    Welcome to Apple Support Communities.
    The article linked below provides troubleshooting tips that’ll likely resolve the issue that you’ve described, where deleted files appear to be taking up space on your iPhone 5.
    If you get a "Not enough free space" alert on your iPhone, iPad, or iPod touch - Apple Support
    So long,
    -Jason

  • How do you clear the "Used supplies in use" message

    I had a Laserjet 1525nw printer replaced under warranty.  The service folks re-installed my original cartridges but now I get the Used Supplies in Use message and I cannot ge the information on how much supply is left in each cartridge.  How do I clear this message?

    Hi dgaraux1,
    Here is a link to a support document that will help interpret control panel and status alert messages. You exact status message in listed in the document says there is not required action on your part.
    Hope this is helpful.
    If I helped you at all it would be great if you clicked the blue kudos star!
    If I solved your post please mark it as solved to help others.
    I'm a printer tech with HP.

  • HT1212 I just bought a used i pod touch from work but the screen says Ipod is disabled, how do i clear that to get back and enter in the passcode

    I just bought a used i pod touch from work but the screen says Ipod is disabled, how do I clear that to get back and eneter in the passcode?

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                          
    If recovery mode does not work try DFU mode.                         
      How to put iPod touch / iPhone into DFU mode « Karthik's scribblings

  • I have deleted all my mails yet the phone shows 4 gb memory used how do i clear this

    I have deleted all my e-mails on my phone,yet the memory shows 4 gb used how do i clear this

    I don't see an issue, but if you mean why didn't you get most of your memory back you need to see what else is using storage. Go to Settings/General/Usage. Wait a bit for it to calculate storage allocation, then when it finishes you can see how much storage each app uses.

  • How do I clear recently used profile photos?

    How do I clear recently used profile photos?

    You only remove bookmarks if you delete bookmarks in a smart folder. If you delete that folder then you delete the smart bookmark and not the bookmarks in the list. A smart bookmark is a query and the result of the query is shown as the content of such a folder. A long as such a gives a result then you see content in the folder, so the only way not to see those bookmarks is to remove the smart bookmark.

  • How can I clear the 'Index found' flag using Flexmotion 5.2?

    When using the 'find index' VI, the motor doesn't physically stop until a few steps after the index, even with the step rate dropped right down to 5 steps a second. (I have no idea whether this is normal or not - the axis is set to Halt on stop, so I would have thought not, but that's what it's doing!)
    This would be ok if I could clear the "index found" flag, drop the step rate down to one a second and do another index find in the opposite direction.
    How do I clear the Index found flag?
    Mike
    Mike Evans
    TRW Conekt
    N.I. Alliance Member, UK
    http://www.Conekt.net

    The "index found" flag will be cleared when you start a new flex_find_index command.

  • I suddenly have 20 gig of used capacity classified as "other.  can't clear it by sync.  what is it?  how can i clear it?

    i suddenly have 20 gig of used capacity classified as "other" on my 3g iphone.  can't clear it by sync.  what is it?  how can i clear it?

    That usually indicates corrupted data. You need to restore it in iTunes on your computer then reload your most recent backup.

  • Hello, I have installed a new Laserjet Pro M1217nfl using Wi-Fi. My laptop prints everything e-mails, Word documents etc. My iPad 3 (latest issue) only prints documents using Wi-Fi so has clearly recognised the printer. How can I prin e-mails using iPad 3

    Hello, I have installed a new Laserjet Pro M1217nfl using Wi-Fi. My laptop prints everything e-mails, Word documents etc. My iPad 3 (latest issue) only prints documents using Wi-Fi so has clearly recognised the printer. How can I print e-mails? Thanks.

    In the email you want to print, on the top right there is an arrow. Click that and an option should appear that says print. That should work. Have you already tried that?

Maybe you are looking for