This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField problems

 
Alex Rugav
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do you set the size of a jTextField so that it does keep on accepting input e.g name and password textfields

how do you also make the JTextfield accept text only denying numbers and alphanumeric e.g for a name JTextField.
 
Li Richriver
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

JTextField TextField = new JextField( 10 );
 
Michael Dunn
Ranch Hand
Posts: 4632
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well im sure there are set methods for the JTextfield class..

but you could create your own.

like...

public void increaseSize(JTextfield t)
{
// im not sure how to aquire the old size so you can increase by
// how ever much you need to..

}

but somthing along those lines

then you could have a method called

public void checkForNumbers(JTextfield t)
{
String A = t.getText();

for(int i = 0; i<A.length(); i++)
{
//again i don't know what syntax to use.
// but you have to compare each char at A.charAt(i);
// to see if it is an integer or not.
}
}

hope this kinda helps you lol.

-Justin-
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic