What is a simple way to create a text field (or such) that only allows the user to enter ints/doubles in Java?
问题 I am looking for a way to ensure that my text field (JTextField, JFormattedTextField) is returning a double or int rather than a string when I call .getText(). What is the best way to do this (if possible)? Thanks! badPanda :D 回答1: Register InputVerifier and call method getValue from JFormattedTextField public class FormattedTextFieldVerifier extends InputVerifier { public boolean verify(JComponent input) { if (input instanceof JFormattedTextField) { JFormattedTextField ftf =