ok.
when I call
myVar.getText(), I get nothing returned unless I use setText() to set
the text of the textfield....
Thanks for the help!
this is the jtextfield class...
----------------------------------------------------
public class TextField3Nums extends JTextField implements
FocusListener{
public static String m_strVal;
public TextField3Nums(String str) {
super(str);
m_strVal = str;
this.addFocusListener(this);
}
public void focusGained(FocusEvent e) {}; // not needed
public void focusLost(FocusEvent e) {
// do checking
if (this.getText().length() == 0){
//set default value on exit from field
this.setText(m_strVal);
}
}
protected Document createDefaultModel() {
return new PlainDoc3Nums();
}
static class PlainDoc3Nums extends PlainDocument {
public void insertString(int iOffset, String str, AttributeSet
ats)
throws BadLocationException {
char[] insertChars = str.toCharArray();
boolean valid = true;
boolean fit = true;
if (insertChars.length + getLength() <= 4) {
for (int i = 0; i < insertChars.length; i++) {
if (insertChars[i] == '.'){
valid = true;
break;
}
if (!Character.isDigit(insertChars[i])) {
valid = false;
break;
}
//limit to 3 numbers only, . not to be included
if (Character.isDigit(insertChars[i])){
if (insertChars.length + getLength() == 4){
if (!this.getText(0,3).contains(".")){
valid = false;
break;
}
}
}
}
}
else{
fit = false;
}
if (fit && valid){
super.insertString(iOffset, str, ats);
}else if (!fit){
//do nothing
}
if (getLength() == 0){
super.insertString(iOffset, m_strVal, ats);
}
}
//protected void
removeUpdate(AbstractDocument.DefaultDocumentEvent chng){
//super.removeUpdate(chng);
/*if (getLength() == 1){
try{
insertString(1, m_strVal, null);
}catch(BadLocationException ble){
}
}*/
//}
}
}