The DefaultCaret class is not in the javax.swing package. It is in the javax.swing.text package.
Reference: http://docs.oracle.com/javase/7/docs/api/javax/swing/text/DefaultCaret.html
If you're still having problems, please post a Minimal Complete Example that demonstrates the problem. The code snippet you provided is likely not enough for others to help you should your problem persist.