简体   繁体   English

JavaFX:文本区域背景颜色错误

[英]JavaFX: Textarea background color error

Here's the problem:这是问题所在:

I tired to make the textarea from javafx have a black color, so i tried to add the parameter:我厌倦了让 javafx 的 textarea 变成黑色,所以我尝试添加参数:

"-fx-background-color" with the value "black" “-fx-background-color” ,值为“black”

It did change something: Around the text area a black border appeared.它确实改变了一些东西:在文本区域周围出现了一个黑色边框。 I tried to change the background size with:我试图改变背景大小:

"-fx-background-insets" with the value "100" (for testing purposes, i know there are up to 4 values)值为“100”“-fx-background-insets” (出于测试目的,我知道最多有 4 个值)

But nothing visual happend.但没有发生任何视觉上的事情。

However, if i set the value to "-100", the screen 100 pixels outwards of the textarea is painted black.但是,如果我将值设置为“-100”,则文本区域外 100 像素的屏幕将被涂成黑色。 So, in theory, reversed parameter delivers the reversed result of what i want.因此,理论上,反转参数提供了我想要的反转结果。

Therefore i ask: Why is it not working?因此我问:为什么它不起作用? I looked up other solutions, and they do it with the "-fx-background-color" parameter, so what ai missing here?我查找了其他解决方案,他们使用“-fx-background-color”参数来做到这一点,那么这里缺少什么?

Use the following in an external css file: 在外部CSS文件中使用以下命令:

.text-area .content { 
    -fx-background-color: black; 
}

don't forget to include this css file, either through FXML or through code. 不要忘记通过FXML或通过代码包含此CSS文件。 You can use this tutorial . 您可以使用本教程

I just found the solution to change the color of the background of TextArea in JavaFX.我刚刚在JavaFX中找到了改变TextArea背景颜色的解决方案。 Write this in your controller class:把这个写在你的 controller class 中:

textarea.setStyle("-fx-control-inner-background: black;");

I was deep searching on the stackoverflow and eventually found it.我在stackoverflow上进行了深入搜索,最终找到了它。 The link is given below: Textarea javaFx Color链接如下: Textarea javaFx 颜色

Happy coding!快乐编码!

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

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