Autoscroll code isn't working: cannot find symbol - java

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?

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.

Related

Why is setCursor() not working?

I am testing a new aspect of java, by attempting to make a custom cursor for my game, but it seems as I have run into a problem where in my code setCursor(); is bringing up a compiler error, for the reason that it is not seen as a proper piece of code. I was following tutorials and different guides, which all led to the same problem and I have found no answer for my query.
Toolkit toolKit = Toolkit.getDefaultToolkit();
Image img = toolKit.getImage(getClass().getResource("/res/cursor.png"));
Point point = new Point(0, 0);
Cursor cursor = toolKit.createCustomCursor(img, point, "Cursor");
setCursor(cursor);
Hope someone might be able to assist me, thanks in advance.
Notes:
I am running the latest JRE as of now (1.8).
The compiler error being recieved is as follows:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved
compilation problem:
The method setCursor(Cursor) is undefined for the type Main
The problem was solved thanks to MadProgrammer's last comment:
Then, you need to call setCursor with the instance of JPanel - A runnable example would make it easier.
The problem I had encountered was that I had used a JFrame as my container, instead of a JPanel. To fix my previous code I changed my main container to a JPanel, which in return allowed me to use: JPanelName.setCursor();
Edit: With further testing, I also found that a JFrame can still be used the same way as previously mentioned. The problem with my code above was that I was calling for it as JFrame.setCursor();, which was a static call to a non-static method. This then gave me the impression that I should only use setCursor(); (As seen in my query above). Hope this helps anyone who might have some misunderstandings on the setCursor(); method. Thanks again to MadProgrammer for solving the problem.

JComboBox: arrow-button should be shown at any time

If a JComboBox is not selected, the arrow-button on the right is not shown. This leads to the fact that a combo-box cannot be distinguished from a normal textfield.
The question is now: how is it possible to show the arrow-button permanently? I alrady came across BasicComboBoxUI.createArrowButton() etc., but I did not find out the mechanism of hiding / showing the arrow-button.
Can anyoune give me a hint how to show the arrow-button permanently ?
Can you add below code as first line in your main method.
Toolkit.getDefaultToolkit().setDesktopProperty("win.xpstyle.themeActive",Boolean.FALSE);
and then check your program.
sorry for the inconvenience. Everything is clear now. In have been told that we use a special framework which changes the behaviour. This information would have been useful if given to me earlier... :-(

Eclipse Luna no syntax coloring

Well I have a problem with one of my classes in Eclipse. In there I define an inner Enum type.
In the picture you can see one of the enum-Constants:https: //www.dropbox.com/s/z9shh52au35mkzy/Pict1.JPG
Now I wanted to add some code to the "setup()" method. Sadly the syntax coloring for the new code doens't show up and even if I create a syntax error inside, it doesn't recognize it. (it works at other places)
https://www.dropbox.com/s/0t6que0pg1hr1tw/Pict2.JPG (can't put pictures in the question yet, I hope you don't mind if I put links there)
Finally, when I save the file and reopen it, the error behaviour is the same, but my pour code looks like this: https://www.dropbox.com/s/9lqzchv4xrnpau6/Pict3.JPG
As you can see, even in the other enum constants, there is just color at keywords and things outside of methods. (If I remove the added code and reopen, it works as if nothing hab happened)
So my question is, how can I fix this?
Thanks in advance.

sikuli 1.0.2 documentation and ScreenRegion

I'm writing program in Java, using Sikuli. I'm using sikuli-standalone***.jar, and ScreenRegion class inside of it. The problem is in documentation: http://doc.sikuli.org/
I can't find class ScreenRegion there, but I can find Screen, and Region, which have better methods (concluding by their names) than ScreenRegion. But unfortunately I don't have these classes in my library.
Acctually this does not result in compiler error:
Screen screen = screenRegion1.getScreen();
But this does:
Screen screen2 = new Screen();
Error is: "Cannot instantiate type Screen"
ScreenRegions seems OK, but because there is no documentation I don't know how to move/create new ScreenRegion that is moved 50px to the right on global screen.
What should I do?
What I'm doing wrong?
Is there Java documentation for Sikuli?
OK it seems that I haven't seen it first time. This is what I should you (I think):
http://doc.sikuli.org/javadoc/index.html
http://doc.sikuli.org/faq/030-java-dev.html
But these classes does not work with classes in sikuli-standalone, and I'm now totally confused about what should I use. But that's topic for another question.
And this seems to be documentation for sikuli-standalone:
http://code.google.com/p/sikuli-api/w/list

Reposition declarations in Netbeans GUIBuilder

So, I am designing a small Interface for an application with the netbeans GUI-Builder,
and my problem is, that the position of the Swing-Elements - declarations is not changeable? Or at least I don't know how.
My ScrollPane needs the Textarea "inside" it as parameter for construction, but in the generated code the TextArea is declared below the Scrollpane.
I tried changing it with N++ and it worked, but everytime I change the custom code section it replaces the declaration again.
Is there any way to accomplish a custom positioning?
AFAIK, there is unfortunately no way to re-position auto generated code in NetBeans. Have you considered perhaps moving the constructors functionality to another method and calling that after the auto-generated code is finished? Something like scrollPane.setTextArea(textArea);?
There is a similar question concerning moving code on the Oracle forums here.

Categories