I'm trying to develop an app that looks like a terminal console, am using a TextArea for that and my wish is to habe a black background and green text,
The point I want to do this without using any ccs template
I know that my question can look like a duplicated in here:
javafx textarea background color not css
or
JavaFX CSS styling of TextArea does not work
but after reading those and trying what they suggested I found no luck to solve my issue
What I tried so far (Unsuccessfully):
in the FXML:
<TextArea
fx:id="terminalTextArea"
layoutX="14.0"
layoutY="85.0"
prefHeight="64.0"
prefWidth="402.0"
style="-fx-font-family: Consolas; -fx-highlight-fill: #00ff00; -fx-highlight-text-fill: #000000; -fx-text-fill: #00ff00; -fx-background-color:#000000;"
text="Terminal"
AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0">
<font>
<Font name="System Bold" size="14.0" />
</font>
</TextArea>
and in the source-code:
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println("init here");
terminalTextArea.setStyle("-fx-text-fill: black;");
}
The only thing that I get is a bordered color like in the image below:
Best Answer
The recommended way is to use an external CSS file, as in the examples you linked.
If for some reason you don't want to do that, try
in your FXML file, or equivalently
in your controller's
initialize()
method.SSCCE:
StyledTextArea.fxml:
and a test class: