Results 1 to 12 of 12
- 08-11-2011, 07:31 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 76
- Rep Power
- 0
- 08-11-2011, 07:34 PM #2
If you have an integer you want to convert to a string, use the toString method. For example:
int x = 10;
String myString = Integer.toString(x);
Then, to put that string into a textfield, assuming you mean something like a JTextField, simply do textFieldName.setText(myString);
There you go.
- 08-11-2011, 07:38 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 76
- Rep Power
- 0
- 08-11-2011, 07:44 PM #4
you don't need any imports to do the integer to string conversion, its just a part of the Integer class.
In what context are you using your textField. Is this a web application?Last edited by sehudson; 08-11-2011 at 07:47 PM.
- 08-11-2011, 07:51 PM #5
That's strange, your code was: Integer.toString(x);the integer to string conversion, its just a part of the String class.
The String class also has a method to convert an int to a String.
- 08-11-2011, 07:55 PM #6
Member
- Join Date
- Jul 2011
- Posts
- 76
- Rep Power
- 0
- 08-11-2011, 07:57 PM #7
Ok.
So yes, once you convert the Integer to a String, just do the textfieldName.setText(myString) and that should work. If you are using Netbeans, right click anywhere inside the class file and select Fix Imports and it will import any necessary packages.
See if that works for you.
- 08-11-2011, 08:10 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,397
- Blog Entries
- 7
- Rep Power
- 17
- 08-11-2011, 08:20 PM #9
From the Integer class's API doc:
public static String toString(int i)
Java Code:String two = Integer.toString(2); System.out.println("two=" + two); // two=2
- 08-11-2011, 08:20 PM #10
From the Integer class's API doc:
public static String toString(int i)
Java Code:String two = Integer.toString(2); System.out.println("two=" + two); // two=2
- 08-11-2011, 08:27 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,397
- Blog Entries
- 7
- Rep Power
- 17
- 08-12-2011, 02:14 AM #12
Similar Threads
-
Display only certain contents of text file and edit display
By blkshrk81 in forum New To JavaReplies: 1Last Post: 12-01-2010, 06:35 PM -
What is the different between Text format display on web browser and display on midle
By Basit781 in forum CLDC and MIDPReplies: 1Last Post: 05-31-2010, 08:46 AM -
Set of Integers
By rsjava24 in forum New To JavaReplies: 7Last Post: 01-28-2010, 10:29 AM -
How to display a list of items and on click display subitems?
By mandyj in forum New To JavaReplies: 8Last Post: 12-29-2008, 07:12 AM -
Help with Code! Display Array of Strings and Integers - Sorted
By luvjoynt in forum New To JavaReplies: 7Last Post: 04-28-2008, 04:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks