Hello all,

First post having migrated to a new home hopefully

I have a project here Im working on to consolidate my work, Im new to Java and my knowledge is still lacking.

I am working on a simple database of invoices for my Nephew and Im having problems setting up a numeric filter on the 'create invoice' form. I have a long list of work related tasks which need to be filled in one by one if the work has been done. No prizes for guessing, each of these item are represented by a label and a JTextField holding the current value.
At the bottom there is a total. When this screen is first displayed each of the TextFields has the value 0.00 in because its a new Invoice. I wanted each value in each textfield to show the following behaviour,
As the person types in a new value, once the value looses focus, the value is examined and if there is no decimal point and 2 digits after then it adds them, if there is one it adds a '0' also if the string starts with a decimal point then the function adds a zero - so,

12.1 becomes 12.10,
.02 becomes 0.02
.2 becomes 0.20

So I thought this would work,

Code:
DocumentFilter numericFilter = new DocumentFilter(){   

        @Override
        public void insertString(DocumentFilter.FilterBypass fb, int offset,
                String string, AttributeSet attr)
                throws BadLocationException {
            fb.insertString(offset, string.replaceAll("[^\\d]", ""), attr);
        }

        @Override
        public void replace(DocumentFilter.FilterBypass fb, int offset, int length,
                String text, AttributeSet attrs)
                throws BadLocationException {

            fb.replace(offset, length, text.replaceAll("[^\\d]", ""), attrs);
        }
    };
....and it does, sort of up to a point but it allows for more than one decimal point? and no adding of zeros ?

So I've looked around for a regEx that will work and Im getting no where -

I'm starting to think that maybe I could do this the old way in a set of If....then.... statements might be a better way.

Anyway, over to this community, my name is Phil, Im a very old hand at programming but new to Object Orientated Java, so a little out of my depth at the moment> ;-)