Hello,
I am trying to make a variant of the JTextField one that accepts only integers and is limited to 6 numbers only, the part where it is only integers i think is correct, but i want someone to tell me if my keyTyped method is correct here or not?
Regards,Code:import javax.swing.JTextField;
import java.awt.event.KeyEvent;
public class JIntTextField extends JTextField
{
private int column;
private final static String nonInt = "`~!@#$%^&*()_+=\\|\"':;?/>.<, ";
public JIntTextField (int column)
{
super(column);
}
[B]public void keyTyped (KeyEvent e)
{
if (this.getText().length() > 6)
{
e.consume();
return;
}
}[/B]
public void processKeyEvent (KeyEvent e)
{
char c = e.getKeyChar();
if ((Character.isLetter(c) && !e.isAltDown()) || nonInt.indexOf(c) > -1)
{
e.consume();
return;
}else{
super.processKeyEvent(e);
}
}
}

