Results 1 to 12 of 12
  1. #1
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Using JTextArea for output

    Hie guys

    I want to use JTextArea with it's multiple lines to display information. Is this possible? If so how can this be done.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Just use the EOL character which is \n. That is if you mean you want

    line 1
    line 2

    If you mean you want the text to wrap them look in the API for the appropriate method.

  3. #3
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    What about the action listener. What do I use to listen in a situation where information is coming from an array that is being constantly populated?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Huh?

    Can you provide a better explaination of what you are trying to do.

  5. #5
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Sorry about that, it's late and I am getting tired.

    Basically all I am trying to do is add an action listener to a JTextArea. The plan being to print out lines of text to the screen.

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    That is not a better explaination. Now you no longer mention the array that you mentioned earlier. What has the array got to do with it? When I asked for a better explaination I meant what are you trying to achieve not how are you trying to do it.

  7. #7
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    @Junky, sorry about that. I have an arrayList that contains 20 Strings. I want to pull out the contents of that Array and display them on the GUI. I thought that JTextArea would be best for this.

    Now the question I really have is what kind of action listener I should add to the JTextArea so I can accomplish this.

    I hope that is a bit clearer.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    11

    Default

    Why not use a button and click it to populate the text area.

  9. #9
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Would I be okay to to listen for InputMethodTextChanged and then use setText() to put the text in?

  10. #10
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    11

    Default

    Not quite sure I know what you mean. You can set it to originally set the text area with the arrays contents and have a button to refresh the text area by clearing it then re filling it with the array contents. Someone else may had better suggestions for auto refreshing with out using a button, perhaps you can have a thread monitor changes to the array list and when they change refresh the text area. Not sure if that would side problems with swing though.

  11. #11
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Thanks for that guys. I seem to have managed to get things connected. A problem has arisen now.

    I want to write a method that checks everything in an array, assigns it to a single string variable, separating each item onto a different line. Is this possible, if so how do I do it.

  12. #12
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    No worries guys this question has now been resolved.
    Last edited by africanhacker; 03-23-2011 at 10:00 AM.

Similar Threads

  1. Replies: 0
    Last Post: 09-30-2010, 08:16 PM
  2. Need help with printing console output to JTextArea
    By ShinTec in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2010, 10:10 AM
  3. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 08:51 PM
  4. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-26-2009, 12:44 AM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 02:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •