There are many frameworks available out there for swing validation, like
Simple Validation and
JGoodies Validation and both being open source. But it looked to me, using these frameworks would require me to change a lot of my existing GUI code. And being a NetBeans user this looked tedious to me(as most of the GUI code is generated by the IDE). Then I came across Michael Urban's post - "
Building a Swing Validation Package with InputVerifier". I have just extended his implementation to suit my needs, like instead of showing a popup for the error message, I wanted an icon painted right in the textfield like in netbeans.
P.S. The GTK Look and Feel does'nt allow a custom background in the JTextField. If you run this application under a different look and feel you could see the background color changing as well.