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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField problems" Watch "JTextField problems" New topic

JTextField problems

Alex Rugav

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

Joined: May 02, 2006
Posts: 1

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

Joined: Jun 09, 2003
Posts: 4632
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.


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.


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

Joined: Jul 11, 2001
Posts: 15302

Moving to the Swing forum.

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: JTextField problems
jQuery in Action, 3rd edition