import java.text.NumberFormat; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.text.NumberFormatter; public class NumberTextFieldExample { public NumberTextFieldExample(){ init(); } private void init() { NumberFormat format = NumberFormat.getInstance(); format.setGroupingUsed(false); NumberFormatter formatter = new NumberFormatter(format); formatter.setAllowsInvalid(false); JFormattedTextField field = new JFormattedTextField(formatter); JFrame frame = new JFrame("Zahlen-Textfeld"); frame.add(field); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new NumberTextFieldExample()); } }