This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java Micro Edition and the fly likes Checking TextField input constraints Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Checking TextField input constraints" Watch "Checking TextField input constraints" New topic
Author

Checking TextField input constraints

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
(A bit long-winded, but a simple question...)

I've created TextField using:

tf2 = new TextField("Enter whatever:", null, 15, TextField.PASSWORD | TextField.NON_PREDICTIVE);

Later on in my code, I want to check whether tf2 has the PASSWORD contraint.

Because I also included the NON_PREDICTIVE constraint, the following detection code doesn't work:

if (tf2.getConstraints() == TextField.PASSWORD) {
//code a
}
else {
//code b
}

So what's the correct way to detect?

Thanks,
James
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
if ((getConstraints() & PASSWORD) == PASSWORD) {
//code a
}
else {
//code b
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Checking TextField input constraints
 
Similar Threads
How to set JTextField with the name in a String
getting null pointer exception
Constant width and height of the textfield
illegalaccessException
how to subtract decimal????