This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTextField problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField problems" Watch "JTextField problems" New topic
Author

JTextField problems

Alex Rugav
Greenhorn

Joined: May 03, 2006
Posts: 19
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

Joined: May 02, 2006
Posts: 1

JTextField TextField = new JextField( 10 );
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/DocumentFilter.html
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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-


You down with OOP? Yeah you know me!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Moving to the Swing forum.


GenRocket - Experts at Building Test Data
 
 
subject: JTextField problems
 
Similar Threads
Search GUI: using JTextField vs. JComboBox
java program to create a file from user inputs.
text editing
jTextfield problems
Difference between JFormatterTextField and JTextField