JavaFX TextArea setCursor无法正常工作 [英] JavaFX TextArea setCursor not working

查看:166
本文介绍了JavaFX TextArea setCursor无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在让setCursor()在TextArea中正常工作时遇到问题。我没有看到与此相关的任何其他搜索结果,并且可能做的很愚蠢,因为还没有其他人解决过这个问题。我尝试了其他选择,但没有运气。下面是一些尝试:

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:

在下面进行编码可以使setCursor仅影响外部边缘。

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

textArea.setCursor(Cursor.DEFAULT);

在FXML中,如果将它与Scene Builder一起添加,则会得到以下内容。

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?>

然后它给了我一个错误,说: FXML无法创建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.

我知道ComboBoxes,必须执行以下操作:

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

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

是否有某种方法可以使TextArea正常工作?

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

谢谢!

推荐答案

您的FXML解析对我来说还不错,尽管它没有有预期的效果。我不确定为什么会给您带来错误。

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

它不生成所需光标的原因是 Text 节点被放置为 ScrollPane 的内容。光标默认是在该 Text 节点上设置的,因此,如果直接将光标设置在 TextArea

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.

最简单的方法是使用外部CSS文件:

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

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

这篇关于JavaFX TextArea setCursor无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆