3 Replies - 1593 Views - Last Post: 13 May 2010 - 11:47 AM Rate Topic: -----

#1 TheRaiderNation  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 81
  • Joined: 11-January 10

Reading in one token at a time

Posted 12 May 2010 - 06:16 PM

So I'm using Netbeans right now and I'm attempting to read 1 token at a time from a textField, but I don't know the method. In jcreator there was a library I had that allowed for a .readToken(), which would read in words separately. But for the textField the only method I know of is .getText(), but that just gives me everything typed into there, not just one word at a time. I've tried looking for the method but can't find it anywhere. Anyone know what it is, if there is one? Thanks.
Problem solved. New question at post 3.

This post has been edited by TheRaiderNation: 12 May 2010 - 09:23 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Reading in one token at a time

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10821
  • View blog
  • Posts: 40,340
  • Joined: 27-December 08

Re: Reading in one token at a time

Posted 12 May 2010 - 06:37 PM

I think you will find the StringTokenizer class helpful here, as you can pass a String and have the Tokenizer return tokens based off of a delim.
Was This Post Helpful? 1
  • +
  • -

#3 TheRaiderNation  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 81
  • Joined: 11-January 10

Re: Reading in one token at a time

Posted 12 May 2010 - 09:22 PM

That worked perfectly thanks. One more question though. So now I have it all working well, just need to add in code to check for punctuation and it's perfect. What I want to know is how to set jTextField property to start a new line when the user is typing something in.
So say my jTextField is:
+-----------+
|
|
|
|
+-----------+
how do I get it to start a new line when it hits that right border?
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Reading in one token at a time

Posted 13 May 2010 - 11:47 AM

You can't with a JTextField...By nature it can only hold one line of text:
http://java.sun.com/...JTextField.html

To do multiline text field, use a JTextArea. To make it word wrapping, use setWrapStyleWord(true):
http://java.sun.com/.../JTextArea.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1