Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 51

Thread: resetting label text alongside gui

  1. #26
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    Quote Originally Posted by BinaryDigit09 View Post
    Ya, I pointed that out to you several posts ago.
    oops i just realised. how do i fix this?

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Don't create new labels, reuse the existing ones.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    if i wanted to use correctLabel how would the code be written?

    im not too sure.. any examples?

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Can you make and post a SMALL, simple program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #30
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    u can see the problem, i just need help with that one line of code.

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    What one line of code? Please post the line of code that you are asking about.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #32
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

                        footer.add(new JLabel(butClicked.getText()));
    Last edited by newtolearningjava; April 26th, 2014 at 06:01 PM.

  8. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    The fix for that statement is to remove it:
      //                 footer.add(new JLabel(buttonClicked.getText()));
    so that it does NOT add a new JLabel.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #34
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    nn nm
    Last edited by newtolearningjava; April 26th, 2014 at 06:01 PM.

  10. #35
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Then use the variable: correctLabel to show the results. Don't create a new JLabel.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #36
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    i have done

    but this only prints one value and then the next how do i get it to be 1 2 3 4
    Last edited by newtolearningjava; April 26th, 2014 at 06:01 PM.

  12. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    An example of what?
    Here's how to set the value of correctLabel from the value in buttonClicked:
      correctLabel.setText(buttonClicked.getText());
    If you need more: make and post a SMALL, simple program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #38
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    please see post#36

  14. #39
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Then see posts #29 and end of #37
    If you don't understand my answer, don't ignore it, ask a question.

  15. #40
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    lol ur funny one aint ya.

  16. #41
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Are you asking how to concatenate a new String to the end of the String currently being shown?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #42
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    yes

  18. #43
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Use the String concatenation operator:
    String x = "1";   // define x and give it a value of "1"
    x  = x + "2";     //  now x has value of "12"
    If you don't understand my answer, don't ignore it, ask a question.

  19. #44
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    dont worry your on a different topic to me all i was is the code to disaplay 1 2 3 4 not 1 then 2 then 3

  20. #45
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Use concatenation so the display will be:
    1
    then
    12
    then
    123
    then
    1234
    etc
    If you don't understand my answer, don't ignore it, ask a question.

  21. #46
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    but i need the values from from the buttonClicked what is in post#43
    Last edited by newtolearningjava; April 26th, 2014 at 06:02 PM.

  22. #47
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    Something like this:
    get value from buttonClicked into x
    get value from label??? into y
    concatenate x to end of y: y = y + x
    set value for label??? from new value of y
    If you don't understand my answer, don't ignore it, ask a question.

  23. #48
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    im not sure i am confused, before i changed the code from
         footer.add(new JLabel(buttonClicked.getText()));

    to

      correctLabel.setText(buttonClicked.getText());

    the label was showing 1 2 3 4 5

  24. #49
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: resetting label text alongside gui

    the label was showing 1 2 3 4 5
    What is the variable name of "the label" that you are talking about?
    I thought that was what you wanted in the label.

    Without a small, complete program that compiles, executes and shows the problem, this is getting to be a waste of time.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #50
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: resetting label text alongside gui

    "correctLabel"

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Re: Resetting Accumulator after first itterneration
    By morrism35 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 2nd, 2013, 07:22 PM
  2. Text output in GUI
    By andreas81 in forum Java Theory & Questions
    Replies: 4
    Last Post: June 26th, 2013, 09:36 AM
  3. Button Text into Label text
    By bluewhale in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 6th, 2011, 10:15 AM
  4. Can't set label text from a Jbutton
    By VBGuy in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 8th, 2010, 10:55 AM