1

I have an ArrayList with values in them, but I want to collect the weight of the ID which is to be inputted into the textfield, how can I make sure that the textfield either only allow integer inputs or verifies that there are not letters or symbols in the text?

ArrayList<String> dt = new ArrayList<>();  
for (int i = 0; i < dt.length; i++) {
                ID[i] = new JLabel();
                ID[i].setText(dt[i]);
                Pl.add(ID[i]); //PL is a panel

            tf[i] = new JTextField();      
            Pl.add(tf[i]);
            ID[i].setVisible(true);
            tf[i].setVisible(true);
        }
  • 1
    You can use a DocumentFilter or InputVerify or simply try converting the returned text can be pared to an Integer – MadProgrammer Jan 23 '19 at 01:40
  • 3
    Possible duplicate of [Is there any way to accept only numeric values in a JTextField?](https://stackoverflow.com/questions/1313390/is-there-any-way-to-accept-only-numeric-values-in-a-jtextfield) – PM 77-1 Jan 23 '19 at 01:40

0 Answers0