Adding actionlistener to JTextArea

I'm trying to add an actionListener to my JTextArea, so that when the user hits 'enter', the action occurs.
sort of like this:
JTextArea.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ??????) {
doSomethingToTextArea();
but I'm having problems (e.g. how to make enter the action event, and some problem that says JTextArea can't use actionlisteners???)
any ideas?
thanks,
n00bProgrammer

Like serveral of the more complex swing gadgets the JTextarea uses model/view architecture. In this case the model behind the textarea is a Document, and the text change listener needs to be added to the Document, not the gadget itself. i.e. area.getModel().addDocumentListener();
However JTextArea still inherits the methods of java.awt.Component including addKeyListener();

Similar Messages

  • Add a actionlistener to JTextArea and print out string when  the user input

    Hello:
    I got a problem to add a actionlistener to JTextArea and print out string which from the user input a sentence and after the user press the "enter".
    Could anyone help me please?
    Thanks
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JScrollBar;
    public class PanelDemo extends JFrame {
       private static JTextArea tAreaUp, tAreaDown;
       private BorderLayout layout;
       private static String strings;
       public PanelDemo()
          super( " test " );
          Container container = getContentPane();
          layout = new BorderLayout();
          container.setLayout( layout );
          tAreaUp = new JTextArea(2,1);
          tAreaUp.setLineWrap(true);
          tAreaUp.setWrapStyleWord(true);
          tAreaUp.setEditable(false);
          tAreaUp.append("I am testing ");
          tAreaUp.append("I am testing");
           JScrollPane scrollPane = new JScrollPane(tAreaUp);
           scrollPane.setVerticalScrollBarPolicy(
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
           scrollPane.setPreferredSize(new Dimension(250, 250));
          tAreaDown =new JTextArea(2,1);
          tAreaDown.setLineWrap(true);
          tAreaDown.setWrapStyleWord(true);
          tAreaDown.addActionListener(new TextAreaHandler());
          JScrollPane scrollPane2 = new JScrollPane(tAreaDown);
          scrollPane2.setVerticalScrollBarPolicy(
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
          container.add( scrollPane, layout.CENTER );
          container.add( scrollPane2, layout.SOUTH );
          setSize( 300, 300 );
          setVisible( true );
         //private inner class for event handling
         private class TextAreaHandler implements ActionListener{
              //process textArea events
            public void actionPerformed(ActionEvent e){
               strings=e.getActionCommand();
                System.out.println(strings);
       public static void main( String args[] )
          PanelDemo application = new PanelDemo();
          application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }

    Thanks for your help, but I still got a question for you.
    Do you think the way I register the even handler to the TextArea is correct?
    Because the compailer complains about that which like
    "D:\101\fig13_27\PanelDemo.java:43: cannot resolve symbol
    symbol  : method addActionListener (PanelDemo.TextAreaHandler)
    location: class javax.swing.JTextArea
          tAreaDown.addActionListener(new TextAreaHandler());

  • Added actionListener, then GUI broke

    Hi,
    1. first i ran my menu GUI, it worked fine
    2. then i added the actionListener code... now she no workie...
    what did i do wrong???
    ERROR MSG:
    C:\jLotto\LotFrame.java:34: cannot resolve symbol
    symbol : class ActionListener
    location: class LottoFrame
              new ActionListener(){
    ^
    1 error
    Tool completed with exit code 1
    import javax.swing.JFrame;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    import java.awt.Event;
    import javax.swing.JOptionPane; //print menu trial run
    public class LotFrame extends JFrame
      // Constructor
      public LotFrame(String title)
        setTitle(title);                             // Set the window title
        setDefaultCloseOperation(EXIT_ON_CLOSE);     // handle exit operation
        setJMenuBar(menuBar);                        // Add the menu bar to the window
        //MAIN MENU
        JMenu fileMenu    = new JMenu("File");          // Create File menu
        JMenu findMenu    = new JMenu("Find");
        // Construct the file pull down menu
        newItem   = fileMenu.add("New");             // Add New item
        openItem  = fileMenu.add("Open");            // Add Open item
        closeItem = fileMenu.add("Close");           // Add Close item
        fileMenu.addSeparator();                      // Add separator
        saveItem  = fileMenu.add("Save");            // Add Save item
        saveAsItem= fileMenu.add("Save As...");      // Add Save As item
        fileMenu.addSeparator();                      // Add separator
        printItem.addActionListener(
               new ActionListener(){
                    public void actionPerformed( ActionEvent e )
                         JOptionPane.showMessageDialog( LotFrame.this,
                         "adding actionListener at end of GUI setup",
                         "action at end", JOptionPane.PLAIN_MESSAGE);
                    }//end of actionPerformed
              }//end of actionLinstener
         );//endof .addActionListener
       printItem = fileMenu.add("Print");           // Add Print item
        menuBar.add(fileMenu);                       // Add the file menu
        menuBar.add(findMenu);
      }//end of constructor
      private JMenuBar menuBar = new JMenuBar();     // Window menu bar
      // File menu items
      private JMenuItem newItem, openItem, closeItem, saveItem, saveAsItem, printItem;
    }//end of class LotFrame

    java.awt.event.*;
    import java.awt.Event;

  • Adding actionListener to JComboBox

    Hi there
    I have added actionListener to a JComboBox. I only want the actionPerformed() get called when the user choose the item in the JComboBox, however, it also get called whenever I change the items in the JComboBox.
    I have tried to call the ActionEvent.getID() method to identify the action, however, changing the items and choosing the item give me the same ID - 1001.
    Has anyone got this problem before? How did you solve it?
    Should I use other Listener for listening only the choosing event?
    In advance thanks!
    From
    Edmond

    I had many problems using actionListeners with JComboBox because it gets called all the time, I have had much better luck using mouseListener and the events getClickCount() method for single and double click selections, this avoided many of the problems for me.

  • Adding scrollbars in jtextarea

    can any one tell me the method of adding scrollbars in jtextarea such that they are enabled when required means initially disabled but when the text goes long they are enabled.
    farhan

    Add ur JTextArea in a JScrollPane by doing this :
    JScrollPane jsp = new JScrollPane(JScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    //then add ur Jtext hereMaz -

  • Adding Image to JTextArea

    Hello All,
    I need to add an Image to a JTextArea. Any ideas plz.
    best wishes
    Issac

    But I have read that all Swing Components, which extend from JComponent >can have other components added to them, because the JComponent class >extends from java.awt.Container and thus have a add method. I tried using t>he add method, but it didnt work. So I tried it here.Don't believe everything you read!!!!! JTextArea is meant to be a simple editor and is not meant to handle what you are trying to do.

  • Adding actionlistener to menuItem

    hi...i'm trying to add an actionListener to a menuItem. i looked at the tutorial on "how to use menus" but i cant seem to execute the menuitem. here's my code...
    public class Controller implements ActionListener
        GUI gui;
        public Controller(GUI g)
            gui = g;
            gui.menuItem.addActionListener(this);
        public void actionPerformed(ActionEvent e)
            gui.menuItem = (JMenuItem)(e.getSource());
            if (gui.menuItem.getText().equals("New Database"))
                System.out.println("Hello");
    }where the class GUI is where the menItems have been added to the menus. i'm just trying out for one menuItem first but i wont get the "hello" printed on the screen...can someone give me some assistance on this given that i havent used JMenuItems before...thx in advance...

    As carnickr said we really need the source from GUI to be able to help you more. Even without looking at GUI it's apparent that you're methodology is lacking. Depending on design and requirements I can think of many different ways you might need to handle menu item actions. I can't think of a single one that would involve comparing the text, which is what you're doing.
    First of all, adding a listener to a public field of a different class is inherently the product of a flawed design or bad design itself. Your code should look more like this:
    JMenuItem newDatabase = new JMenuItem("New Database");
    JMenuItem openDatabase = new JMenuItem("Open Database");
    JMenuItem closeDatabase = new JMenuItem("Close Database");
    ActionListener listener = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              if (e.getSource() == newDatabase) {
                   System.out.println("New database clicked");
              } else if (e.getSource() == openDatabase) {
                   System.out.println("Open database clicked");
              } else fi (e.getSource() == closeDatabase) {
                   System.out.println("Close database clicked");
    newDatabase.addActionListener(listener);
    openDatabase.addActionListener(listener);
    closeDatabase.addActionListener(listener);Obviously an anonymous class is not always appropriate. The important thing here is that you're comparing the reference to see if it's the same Object, not trying to compare the text. If you post GUI and a little more about what you're trying to do we can try and give you some pointers on how to design it better.

  • Adding ActionListener to JMenu

    Is it possible to add actionListener to Jmenu object
    for example File, Format, Exit these are Menus added in the menuBar not menu items
    on clicking the Exit the frame shuld get closed.
    For detecting the action clicked on the Menu shall i use actionListener?
    I have tried using MenuListener its getting invoked on selection
    I dont want it on selection , I want the frame to be displayed only on clicking that menu.

    Alas, whilst a JMenu is-a JMenuItem (the Composite Pattern at work), it doesn't function entriely like on,
    and registering ActionListeners with a JMenu doesn't work. Try MenuListener:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class ActionExample {
        public static void main(String[] args) {
            Action sample = new SampleAction();
            JMenu menu = new JMenu("Menu");
            menu.setMnemonic(KeyEvent.VK_M);
            menu.add(sample);
            menu.addMenuListener(new SampleMenuListener());
            JToolBar tb = new JToolBar();
            tb.add(sample);
            JTextField field = new JTextField(10);
            field.setAction(sample);
            JFrame f = new JFrame("ActionExample");
            JMenuBar mb = new JMenuBar();
            mb.add(menu);
            f.setJMenuBar(mb);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(tb, BorderLayout.NORTH);
            f.getContentPane().add(field, BorderLayout.SOUTH);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    class SampleMenuListener implements MenuListener {
        public void menuSelected(MenuEvent e) {
            System.out.println("menuSelected");
        public void menuDeselected(MenuEvent e) {
            System.out.println("menuDeelected");
        public void menuCanceled(MenuEvent e) {
            System.out.println("menuCanceled");
    class SampleAction extends AbstractAction {
        public SampleAction() {
            super("Sample");
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt S"));
            putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
            putValue(SHORT_DESCRIPTION, "Just a sample action");
        public void actionPerformed(ActionEvent evt) {
            System.out.println("sample...");
    }

  • Adding actionListener to a button

    pls i want to create an applet with buttons rectangle,circle,and polygon and having a textArea.when someone clicks on the rectangle buttons it draws a rectangle,on the circle buttons it draws a circle and on the polygon button it draws a polygon.pls i have already created the user interface how do i add the actionListeners to the respective buttons and reggister them.

    Hi,
    try something like this:
    JButton jButton1 = new JButton("yourbutton");
    jButton1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent evt) {
                    someMethodThatDoesWhatYouNeed();
    });this is just a way to do it, there are other ways, just look around in the forum to discover them.
    JoY?TiCk

  • Adding ActionListener to JPanel or equivalent

    Hi all.
    I am trying to add an actionListener for mouse clicks on a JPanel, ideally using something like this:
    panel.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e)
              //do something
       });However, JPanel does not implement addActionListener, and as far as I can see the only components which do are buttons, radio buttons and the like.
    I tried extending JPanel to implement ActionListener, but had no success.
    Is there an easy way to monitor for mouse clicks on a JPanel or container? Bearing in mind there will be several of these containers at different locations, so using a global mouse listener would not be useful.
    Thanks

    Hi all.
    I am trying to add an actionListener for mouse clicks
    on a JPanel, ideally using something like this:
    panel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
    //do something
    });owever, JPanel does not implement addActionListener,
    and as far as I can see the only components which do
    are buttons, radio buttons and the like.
    I tried extending JPanel to implement ActionListener,
    but had no success.
    Is there an easy way to monitor for mouse clicks on a
    JPanel or container? Use a MouseListener.
    Bearing in mind there will be
    several of these containers at different locations,
    so using a global mouse listener would not be
    useful.So add individual MouseListeners to each container.
    >
    Thanks

  • Adding actionListener to JOptionPane

    how do you add an actionListener to a JOptionPane?
    im using JOptionPane.showMessageDialog, and i want an event to happen when the user clicks on the "Okay" button

    Can you do something like this instead? Use a showConfirmDialog(...) istead of the showMessageDialog(...), then use the return value to determine which button the user pushed?
    int retValue = JOptionPane.showConfirmDialog(parent, message, Title, JOptionPane.OK_CANCEL_OPTION );
    if (retValue == JOptionPane.OK_OPTION)
      doOkayEvent();
    else
      doNotOkayEvent();

  • Trouble adding actionlistener to a panel in a tabbed pane

    Hi, please help me! this is the code i wrote, with the error given below:
    CODE:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class tabslisten extends JApplet
         JPanel RecPanel;
         GridBagLayout gbl;
         GridBagConstraints gbc;
         public void init ()
              FlowLayout flow;
              flow = new FlowLayout();     
              Container content = getContentPane();
              content.setLayout(new GridLayout());
              JTabbedPane tabpane = new JTabbedPane();
              content.add(tabpane, flow);
              RecPanel = new JPanel();
              recipientDetails();
              tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details");     
         public void recipientDetails()
              JLabel lblRecFName;
              JLabel lblRecLName;
              JTextField txtRecFName;
              JTextField txtRecLName;
              JButton btnValidate;
              gbl = new GridBagLayout();
              gbc = new GridBagConstraints();
              RecPanel.setLayout(gbl);
              lblRecFName = new JLabel("First Name");
              lblRecLName = new JLabel("Last Name");
              txtRecFName = new JTextField(8);
              txtRecLName = new JTextField(5);
              btnValidate= new JButton("Validate");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 8;
              gbl.setConstraints(lblRecFName, gbc);
              RecPanel.add(lblRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 8;
              gbl.setConstraints(txtRecFName, gbc);
              RecPanel.add(txtRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 11;
              gbl.setConstraints(lblRecLName, gbc);
              RecPanel.add(lblRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 11;
              gbl.setConstraints(txtRecLName, gbc);
              RecPanel.add(txtRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 32;
              gbl.setConstraints(btnValidate, gbc);
              RecPanel.add(btnValidate);
              validateAction validateButton = new validateAction();
              btnValidate.addActionListener(validateButton);
         class validateAction implements ActionListener
              public void actionPerformed(ActionEvent evt)
                   Object obj = evt.getSource();
                   if (obj == btnValidate)
                        String fName = txtRecFName.getText();
                        String lName = txtRecLName.getText();
                        if (fName.length()==0)
                             getAppletContext().showStatus("First Name not entered.");
                             return;
                        else if (lName.length()==0)
                             getAppletContext().showStatus("Last Name not entered.");
                             return;
                        else
                             getAppletContext().showStatus("Successful.");
    ERROR:
    tabslisten.java:90: Undefined variable: btnValidate
    if (obj == btnValidate)
    ^
    tabslisten.java:92: Undefined variable or class name: txtRecFName
    String fName = txtRecFName.getText();
    ^
    tabslisten.java:93: Undefined variable or class name: txtRecLName
    String lName = txtRecLName.getText();
    ^
    3 errors
    Press any key to continue...
    I'm sure I'm doing something really stupid, but I don't know what! ANY and ALL help will be appreciated! Thanks!

    I copied your program and ran it. It works fine. Make sure the three variables you made class variables are only defined in one place. (ie you moved them not copied them). Other than that I have no ideas.
    With regards to naming conventions. My only comment is, take a look at the Java API.
    1) classes have uppercased words. Examples from your program - JTextField, Container, FlowLayout, GridLayout...
    2) methods and variable names don't upper case the first word - getContentPane(), setLayout()...
    Here is the program that works for me:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class FirstApplet extends JApplet
         JPanel RecPanel;
         GridBagLayout gbl;
         GridBagConstraints gbc;
         JTextField txtRecFName;
         JTextField txtRecLName;
         JButton btnValidate;
         public void init ()
              System.out.println("hello there");
              FlowLayout flow;
              flow = new FlowLayout();
              Container content = getContentPane();
              content.setLayout(new GridLayout());
              JTabbedPane tabpane = new JTabbedPane();
              content.add(tabpane, flow);
              RecPanel = new JPanel();
              recipientDetails();
              tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details");
         public void recipientDetails()
              JLabel lblRecFName;
              JLabel lblRecLName;
              gbl = new GridBagLayout();
              gbc = new GridBagConstraints();
              RecPanel.setLayout(gbl);
              lblRecFName = new JLabel("First Name");
              lblRecLName = new JLabel("Last Name");
              txtRecFName = new JTextField(8);
              txtRecLName = new JTextField(5);
              btnValidate= new JButton("Validate");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 8;
              gbl.setConstraints(lblRecFName, gbc);
              RecPanel.add(lblRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 8;
              gbl.setConstraints(txtRecFName, gbc);
              RecPanel.add(txtRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 11;
              gbl.setConstraints(lblRecLName, gbc);
              RecPanel.add(lblRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 11;
              gbl.setConstraints(txtRecLName, gbc);
              RecPanel.add(txtRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 32;
              gbl.setConstraints(btnValidate, gbc);
              RecPanel.add(btnValidate);
              validateAction validateButton = new validateAction();
              btnValidate.addActionListener(validateButton);
         class validateAction implements ActionListener
              public void actionPerformed(ActionEvent evt)
                   Object obj = evt.getSource();
                   if (obj == btnValidate)
                        String fName = txtRecFName.getText();
                        String lName = txtRecLName.getText();
                        if (fName.length()==0)
                             getAppletContext().showStatus("First Name not entered.");
                             return;
                        else if (lName.length()==0)
                             getAppletContext().showStatus("Last Name not entered.");
                             return;
                        else
                             getAppletContext().showStatus("Successful.");

  • Adding JButton to JTextAreas

    I'm publishing reports from data onto an uneditable JTextArea (so the user can save it as a text doc if they wish).
    I'd like to have a button next to each report so the user can view the data for that report, but presumably this can't be done on a JTextArea?
    Anyone have any suggestions as to how I can have a 'View data' button, but still be able to save the text of the report?
    Many thanks.

    If you are trying to produce a panel that has a JTextArea and a JButton on it, that is relatively easy to do.
    You cannot put a JButton into a text area but it is easy enough to put it either next to or below the text area and provide the functionality that you are looking for.

  • Adding Actionlistener to a cell in a JTable?

    is this possible? how would i go among doing this?

    use the ListSelectionListener.
    In "valueChanged(ListSelectionEvent e)" you get the row with "e.getFirstIndex()".

  • 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.

Maybe you are looking for