简体   繁体   English

如何更改 JavaFX 2.0 中的插入符颜色?

[英]How to change the caret color in JavaFX 2.0?

We want to migrate a project from Swing to JavaFX as the new UI technology.我们想将一个项目从 Swing 迁移到 JavaFX 作为新的 UI 技术。 As a part of our corporate design, we were changing the caret color in Swing to a light green.作为我们企业设计的一部分,我们将 Swing 中的插入符颜色更改为浅绿色。

How can we alter the color(or maybe also other things about the appearance) of carets in JavaFX 2.0?我们如何改变 JavaFX 2.0 中插入符的颜色(或者可能还有其他关于外观的东西)? I couldn't find any useful information about it.我找不到任何有用的信息。 I saw that it was possible in earlier versions of JavaFX, so i guess there's a way in 2.0 too.我看到JavaFX的早期版本是可以的,所以我猜2.0也有办法。

Kind regards,亲切的问候,

David大卫

In the TextField caret has the same color as text.在 TextField 中,插入符号与文本具有相同的颜色。 You can change them by:您可以通过以下方式更改它们:

    TextField tf = new TextField("Text");
    tf.setStyle("  -fx-text-fill: green");

or globally in css file.或全局在 css 文件中。

Sergey's answer should work fine.. However it does not work with texarea since it is a bug..U can download java fx 2.1 developer preview to make it work with textarea Sergey 的回答应该可以正常工作。但是它不适用于 texarea,因为它是一个错误。您可以下载 java fx 2.1 开发人员预览版以使其与 textarea 一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM