Question

I'm trying to use the standard auto-scroll code I've been seeing copypasta'd everywhere:

    DefaultCaret caret = (DefaultCaret)textarea.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

It's placed in the same place I've seen it placed in other codes, right after the creation of the textarea it's associated with.

However, when I compile the code, it gives me the error "cannot find symbol", and points at all instances of DefaultCaret, much like if I had not imported the proper thing into my code.

I have imported ALL of javax.swing, after doing some researching it seems like the code works fine for everyone else.

Seems like I'm missing something simple, but I have no clue what it could be.

Am I supposed to define it earlier in the code?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top