Decimal « JTextField « Java Swing Q&A





1. Java textfield decimal validation    stackoverflow.com

How can I validate user input contain only 5 digits with 2 decimal. I am using below code to check 5 digits, but how to check 2 decimal.

if (!id.equals("")) {
  ...

2. A textfield that accepts only decimal numbers    coderanch.com

The following may not be 100% correct, but I think it is pretty close. Now, if there is a shorter easier way, I hope someone let's us know. public void CheckingForDecimal() { boolean stillOK = true; int myLength = myTextField.getText().lenth; String TmpBuffer = myTextField.getText(); String myParser = new String(); for (int count = 0; count < myLength; count++) { myParser = ...

3. JTextField and decimal number    coderanch.com

4. Avoid user entering more than 2 decimal figures in textfield    coderanch.com

Hello ! You did not say if you are using swing,AWT or SWT, anyway, I'm using SWT and I believe that basiclly this shuld be in every one of them (maybe a not excactly the same name) Anyway , use this: ( Text myText = new Text(composite,SWT.NONE) ) myText.setTextLimit(2); this will not let the user enter more that 2 digits Hope ...

5. decimal place formatting JtextField    coderanch.com