Results 1 to 7 of 7
  1. #1
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Textfield not displaying correct text

    So i am trying to display some text in a textbox that i pull out of a variable but it does not display the text. When i hit the button that is holding the event, nothing happens but there are no errors. heres what the code looks like around what i want it to do. ContributionlessText is the textfield and less is the value i want displayed in it. again no errors. just nothing happens


    contribution2Button = new JButton();
    contribution2Button.setFont(new Font("Tahoma", Font.PLAIN, 12));
    contribution2Button.setBounds(494, 115, 100, 21);
    contribution2Button.setText("401k input 2");
    panel_1.add(contribution2Button);
    contribution2Button.addActionListener(
    new ActionListener()
    {
    public void actionPerformed(ActionEvent event)
    {


    less = (Double.parseDouble(totalPayText.getText())) - (Double.parseDouble(contributionText.getText()));
    contributionlessText.setText(String.valueOf(less)) ;
    }

    })

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Textfield not displaying correct text

    Probably because you defint the textField twice. Once as a class variable and once as a local variable. Get rid of the local variable.

    If you need more help then post your Short, Self Contained, Correct Example that demonstrates the problem.

  3. #3
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Textfield not displaying correct text

    i declared contributionlessText as a private textField in the beginning of the program and i set up its bounds, etc. a little earlier than the code i posted. I dont think i have declared it as a variable twice?

  4. #4
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: Textfield not displaying correct text

    try with few System.out.println() for values of
    Double.parseDouble(totalPayText.getText()) and Double.parseDouble(contributionText.getText()) to see what those numbers are

  5. #5
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Textfield not displaying correct text

    where would that output to? command prompt?

  6. #6
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: Textfield not displaying correct text

    yes, or if you use ide there must be some output.
    I forgot to mention to put those prints in your action performed method before other code inside

  7. #7
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Textfield not displaying correct text

    ok i use eclipse so it would just output into the text area under the code? i apologize as i am currently not in the location of my developement computer

Similar Threads

  1. frame not displaying correct contents
    By yemista in forum AWT / Swing
    Replies: 5
    Last Post: 10-20-2011, 05:30 PM
  2. Trying to get correct text format in .txt file
    By patriotsfan in forum New To Java
    Replies: 14
    Last Post: 06-06-2011, 02:29 AM
  3. Replies: 3
    Last Post: 11-16-2010, 08:43 AM
  4. Replies: 2
    Last Post: 06-14-2010, 10:18 AM
  5. accessing the text of textfield of one class in another
    By vasavi.singh in forum Advanced Java
    Replies: 3
    Last Post: 04-05-2009, 02:54 PM

Posting Permissions

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