Java 7 to Java 8 issue with setting background color of TextArea and StyleSheets/css

浪尽此生 提交于 2019-12-25 02:07:05

问题


I had a Java FXML application functioning in Java 7u51 that I built in NetBeans 7.4. I have installed Java 8 and NetBeans 8. I recreated my little application in Java 8/NetBeans 8. Everything is working except some of the css styling. Specifically, I have a Text Area.

Here is the Text Area FXML:

<TextArea layoutX="1" layoutY="230" minHeight="120" minWidth="320" editable="false" fx:id="eventWindow" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.bottomAnchor="0.0"/>

Here is the corresponding css styling:

#eventWindow {
    -fx-background-color: black;
    -fx-text-fill: white;
}

When I run the application, the background of my text area stays white! What's frustrating is that other things from my css file are behaving as they should. I have already tried the following:

1) I tried putting this in my css:

.events {
    -fx-background-color: black;
    -fx-text-fill: white;  
}

...and adding 'styleclass="events"' into my FXML.

2) and I tried:

.textarea {
    -fx-background-color: black;
    -fx-text-fill: white;  
}

no dice on either of those.

I have also double-checked to make sure that nothing could be overriding it. And... it's working just fine in Java 7u51.

I know this is not the most critical thing on the planet... but it's driving me nuts!

Thanks in advance! -Adeena


回答1:


The problem is that the TextArea consist of several nodes (TextArea,ScrollPane,Content). To change the background of the content node the following css can be used:

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

The substructure of nodes is explained in the JavaFX css documentation: http://download.java.net/jdk8/jfxdocs/javafx/scene/doc-files/cssref.html#textarea

Here's a link to a related issue: https://javafx-jira.kenai.com/browse/RT-31904




回答2:


in the fxml styleClass="eventWindow"

and then in the css

.eventWindow { -fx-background-color: black; -fx-text-fill: white; }

works for me



来源:https://stackoverflow.com/questions/21944532/java-7-to-java-8-issue-with-setting-background-color-of-textarea-and-stylesheets

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