Results 1 to 5 of 5
  1. #1
    Shin is offline Member
    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0

    Default How can i display a number on a jlabel.

    i just want to know what is the code in getting a numeric value from a textfield and display it on jlabel using checkbox

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: How can i display a number on a jlabel.

    If you're going to put it in a jlabel, it doesn't have to be numeric because both TextFields and JLabels work with Strings. However, if you need the number for a calculation, you'll need to parse it with one of the wrapper classes - Integer, Float, Double, etc...

  3. #3
    Shin is offline Member
    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0

    Default Re: How can i display a number on a jlabel.

    okay i got it now, but how can i send the value of the jtextfield to a jlabel.

    Java Code:
     public void actionPerformed(ActionEvent e)
        {
            
       if (e.getSource() == chk1){
           numcf1 = Integer.parseInt(txttall.getText());
                
           
            }

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

    Default Re: How can i display a number on a jlabel.

    You have already been told. Both textfields and labels use Strings. So all you need to do is get the String from one and pass it to the other.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: How can i display a number on a jlabel.

    JLabel (Java Platform SE 6)

    Have you looked at the API at all? Namely the .setText() method?

Similar Threads

  1. [Urgent Help] JLabel images display
    By baobao816 in forum AWT / Swing
    Replies: 2
    Last Post: 05-12-2012, 10:46 AM
  2. Display number of characters like bar chart
    By Dreaming in forum New To Java
    Replies: 6
    Last Post: 10-17-2011, 07:11 AM
  3. Replies: 14
    Last Post: 09-13-2011, 12:54 AM
  4. Replies: 0
    Last Post: 05-09-2011, 03:41 AM
  5. Replies: 1
    Last Post: 04-28-2010, 12:29 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
  •