Results 1 to 6 of 6

Thread: JTextArea

  1. #1
    larry_d1990 is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default JTextArea

    I'm having a little trouble with the setText method for JTextAreas. Basically I want to setText through the GUI constructor and not a paint method. Here I want to pass a string through the setText method so it can be displayed in the JTextArea. I.E....

    Class GUI....

    public GUI()
    {
    String sValue = "Hello World"
    JTextArea sText = new JTextArea();
    sText.setText(sValue);
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by larry_d1990 View Post
    I'm having a little trouble with the setText method for JTextAreas. Basically I want to setText through the GUI constructor and not a paint method. Here I want to pass a string through the setText method so it can be displayed in the JTextArea. I.E....

    Class GUI....

    public GUI()
    {
    String sValue = "Hello World"
    JTextArea sText = new JTextArea();
    sText.setText(sValue);
    }
    That snippet looks sensible enough to me; b.t.w. you should never set any text in your paint( ... ) method, forget about it. What exactly is your problem? (apart from the fact that your JTextArea is just a local variable).

    kind regards,

    Jos
    Last edited by JosAH; 03-11-2011 at 04:40 PM. Reason: typo ...
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,302
    Rep Power
    20

    Default

    So what's the problem?

    db

  4. #4
    larry_d1990 is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    Well actually it's not a string, within the class. It's a method from another class. I just illustrated incorrectly. Basically, I've got a class Simulator, which creates an instance of a class Prototype()...

    Prototype obj1 = new Prototype();

    ...Prototype class contains a method...

    Public String GetValue()
    {
    return sValue; (note sValue = "helloworld")
    }

    ... so I've got GUI class to contain a JTextArea(which is a global variable) and in my constructor I want it to set the JTextArea to display sValue....

    class GUI...

    private JTextArea stringText;

    public GUI(){...
    stringText.setText(Simulator.obj1.GetValue());
    }

    .... so it gives the result...

    helloworld.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,302
    Rep Power
    20

    Default

    so I've got GUI class to contain a JTextArea(which is a global variable)
    There are no global variables in Java. There are static, or class fields and non-static, or instance fields, and there are local variables.

    db

Similar Threads

  1. JTextArea
    By larry_d1990 in forum Advanced Java
    Replies: 4
    Last Post: 01-11-2011, 05:44 PM
  2. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  3. Tab key in JTextArea
    By KristoZ in forum New To Java
    Replies: 1
    Last Post: 09-25-2009, 07:27 PM
  4. About JTEXTAREA
    By makpandian in forum AWT / Swing
    Replies: 4
    Last Post: 03-19-2009, 06:53 AM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 01: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
  •