JavaFX TextArea setCursor not working

拟墨画扇 提交于 2019-12-08 12:17:46

问题


I am having issues getting setCursor() to work properly in TextArea. I am not seeing any other search results at all for issues with this, and might be doing something silly because no one else has addressed this yet. I have tried different options, with no luck. Here are a few attempts below:

Coding this below makes it so only the outer edges are effected by the setCursor.

textArea.setCursor(Cursor.DEFAULT);

In FXML, I get the following if I add it in with Scene Builder.

<TextArea fx:id="textArea" prefHeight="458.0" prefWidth="766.0">
    <font>
        <Font name="System Bold" size="12.0" />
    </font>
    <cursor>
        <Cursor fx:constant="DEFAULT" />
    </cursor>
</TextArea>

It gives me an error, so I add the import...

<?import javafx.scene.Cursor?>

Then it gives me an error, saying "Instances of javafx.scene.Cursor cannot be created by FXML loader." with no hints provided.

I know for ComboBoxes, I have to do the following:

comboBox.getEditor().setCursor(Cursor.DEFAULT);

Is there some way I have to do this for TextArea to work as well?

Thanks!


回答1:


Your FXML parsed just fine for me, though it didn't have the desired effect. I'm not sure why it gave you errors.

The reason it doesn't generate the desired cursor is that the Text node is placed as the content of a ScrollPane. The cursor is set by default on that Text node, so it isn't inherited if you set the cursor directly on the TextArea.

The easiest way to do this is to use an external CSS file:

.text-area .content {
    -fx-cursor: DEFAULT ;
}


来源:https://stackoverflow.com/questions/25629938/javafx-textarea-setcursor-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!