Ps una forma de hacer eso es crear una clase manejador de eventos de teclado y darsela al la caja para que esa clase maneje dichos eventos y solo permita entrar caracteres deseados.
Por ejemplo:
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author JORGE
*/
public class P extends javax.swing.JFrame {
/** Creates new form P */
public P() {
initComponents();
this.setTitle("Prueba para el proyecto");
ManejoTeclado mt=new ManejoTeclado(this.txf_nom);
this.txf_nom.addKeyListener(mt);
txf_nom.setEditable(false);
txf_nom.setBackground(Color.WHITE);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Código Generado ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txf_nom = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("PRODUCTOS");
jLabel2.setText("PRODUCTO");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(111, 111, 111)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addComponent(txf_nom, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(583, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jLabel1)
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txf_nom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(389, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new P().setVisible(true);
}
});
}
class ManejoTeclado extends KeyAdapter
{
JTextField com;
public ManejoTeclado(JTextField comp)
{
com=comp;
}
public void keyPressed(KeyEvent ke)
{
String cad=com.getText();
if(ke.getKeyCode()>=65 && ke.getKeyCode()<=90)
{
cad+=ke.getKeyChar();
com.setText("");
com.setText(cad);
}
else
{
}
}
}
// Declaración de varibales -no modificar
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField txf_nom;
// Fin de declaración de variables
}
Esto solo permite entrar caracteres de letras minñusculas, ya tu sabrás como manejar el retorno, espacio, coma, etc.
Aunque la p0oner el txf_nom.editable(false); se elimina el cursor; no se como evitar eso, pero te puede servir de guia.
SUERTE!!!