Results 1 to 6 of 6
  1. #1
    PhilJosh is offline Member
    Join Date
    Jul 2012
    Location
    Philippines
    Posts
    2
    Rep Power
    0

    Default Hi! I need immediate help with this please. (JTextArea)

    The variable area is a JTextArea and I declared it inside a class. My problem is that I can't set its text using setText.
    Hi! I need immediate help with this please. (JTextArea)-jaba.png
    Thank you for helping me in advance. Just beep me if something is not clear. I know it's not.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Hi! I need immediate help with this please. (JTextArea)

    Please don't use screen shots...
    What error are you getting?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: Hi! I need immediate help with this please. (JTextArea)

    You gave us a screen shot of some code that does not even include the JTextArea. Can you post some of that code.

    Not only that... but I might be wrong here, but your code that says event.getSource() == go, will never be activiated. Because you nested within another button click if statement. You cannot click on both of them fast enough to have them both equal true. So that is your first problem. If you need to know that addButton has been click, create a boolean variable that will turn true when that button is clicked. Then go event.getSource() == go && addBoolean == true. Aside from that, there is not enough information for me to help you further.

    Oh, and when you post your code, do not post all of it. From those scroll bars, I can see you have a lot of code.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  4. #4
    PhilJosh is offline Member
    Join Date
    Jul 2012
    Location
    Philippines
    Posts
    2
    Rep Power
    0

    Talking Re: Hi! I need immediate help with this please. (JTextArea)

    Quote Originally Posted by kammce View Post
    You gave us a screen shot of some code that does not even include the JTextArea. Can you post some of that code.

    Not only that... but I might be wrong here, but your code that says event.getSource() == go, will never be activiated. Because you nested within another button click if statement. You cannot click on both of them fast enough to have them both equal true. So that is your first problem. If you need to know that addButton has been click, create a boolean variable that will turn true when that button is clicked. Then go event.getSource() == go && addBoolean == true. Aside from that, there is not enough information for me to help you further.

    Oh, and when you post your code, do not post all of it. From those scroll bars, I can see you have a lot of code.
    I figured that out too. I removed the go button after realizing it.
    (Sorry I don't know how will I post some of my code elegantly since I'm new here)
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;

    public class UIMainMenu extends JFrame
    {
    private JButton addButton;
    private JButton sellButton;
    private JButton showInventory;
    private JButton exitButton;
    private JLabel plName;
    private JLabel plQuan;
    private JLabel plNum;
    private JTextField pName;
    private JTextField pQuan;
    private JTextField pNum;
    private JTextArea area;
    private JScrollPane pane;
    private JPanel options;
    private JPanel textFields;
    private int run=1, choice, quan, aw, num=1, i, j, k, l;
    private String name, toOutput;

    public UIMainMenu()
    {
    //some code here
    }

    private class ButtonHandler implements ActionListener
    {
    ArrayList<Ewst> invent=new ArrayList<Ewst>();

    public void actionPerformed(ActionEvent event)
    {
    toOutput="";
    pName.setText(null);
    pNum.setText(null);
    pQuan.setText(null);

    if(event.getSource()==addButton)
    {
    name=pName.getText();
    quan=Integer.parseInt(pQuan.getText());
    Ewst haha=new Ewst(name, quan, num);
    invent.add(haha);
    num++;
    area.setText("Product added.\n");
    }
    //some more code
    }
    }

    There it is. Thanks for the response by the way,

  5. #5
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: Hi! I need immediate help with this please. (JTextArea)

    Ok, first things first. Edit your previous post and add [code] tags to it.

    Second. It does not seem as if you have initialized your Objects. I assume you initialized them in:
    Java Code:
    public UIMainMenu()
    {
    //some code here
    }
    If not, you should do that. If so, then do not worry about this part.

    This might be me... but I have never seen anyone create variables like this:
    private int run=1, choice, quan, aw, num=1, i, j, k, l;, but, if it works, it works.

    Are you able to set the text of at least the area JTextArea? Comment all of the other stuff out and see if you can just set the text of area... also, put a System.out.println("This worked"); in the if(event.getSource()==addButton) statement to see if it is actually be activated. Remember, standard is out is your friend!
    My API:
    Java Code:
    cat > a.out || cat > main.class

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

    Default Re: Hi! I need immediate help with this please. (JTextArea)

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JTextArea
    By johnny157 in forum New To Java
    Replies: 2
    Last Post: 03-03-2011, 10:52 PM
  2. Using JTextArea
    By tnixon22 in forum New To Java
    Replies: 10
    Last Post: 01-23-2011, 08:01 PM
  3. JTextArea
    By larry_d1990 in forum Advanced Java
    Replies: 4
    Last Post: 01-11-2011, 06:44 PM
  4. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 08:51 PM
  5. About JTEXTAREA
    By makpandian in forum AWT / Swing
    Replies: 4
    Last Post: 03-19-2009, 07:53 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
  •