Validar un enter para un TextField
hola, necesito que alguien me diga como hacer para que mi programa realice un procedimiento al terminar de escribir en una caja de texto y dar un enter, urgente, gracias
tienes dos opciones, agregar un oyente a tu JTextField, es decir q cuando des enter (dentro del JTextField) se realice lo q quieras, o simplemente pones por Default un JButton, para q cuandos des enter en cualquier parte se realice lo q quieras.
Para el JTextField puedes hacer esto:
textfield.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ //Aqui haces lo q quieres
}
});
y si en su lugar quiers al JButton por defecto solo haz
getRootPane().setDefaultButton(button);
obviamente button tiene que tener un ActionListener también
Para el JTextField puedes hacer esto:
textfield.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ //Aqui haces lo q quieres
}
});
y si en su lugar quiers al JButton por defecto solo haz
getRootPane().setDefaultButton(button);
obviamente button tiene que tener un ActionListener también