0

Here's the problem:

I tired to make the textarea from javafx have a black color, so i tried to add the parameter:

"-fx-background-color" with the value "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)

But nothing visual happend.

However, if i set the value to "-100", the screen 100 pixels outwards of the textarea is painted black. 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 a i missing here?

PCK4D
  • 1
  • 2

2 Answers2

1

Use the following in an external css file:

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

don't forget to include this css file, either through FXML or through code. You can use this tutorial.

Itai
  • 6,641
  • 6
  • 27
  • 51
  • Ok, that worked. Thanks! Still i'd like to know what didn't work there? – PCK4D Jan 10 '16 at 10:54
  • Look [here](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#text-area) - as far as CSS in concerned, `TextArea` is a `ScrollPane`, that has a `Region` (named `content`) inside it. What you did changed the background color of the outer `ScrollPane`, but that is hardly visible, as it is filled entirely by the `Region`. – Itai Jan 10 '16 at 11:43
  • Well, now i know. Guess you can't rely on the scene builder as much as you like. I'll keep it in mind if something similar happends again. – PCK4D Jan 10 '16 at 16:48
  • Scene Builder has a very nice (and powerful) CSS analyzer tool. You can use it to highlight controls and even parts of controls to see their CSS path. Go to View->Show CSS Analyzer, and you'll have the option to turn your cursor between normal selection and CSS Path selection. – Itai Jan 10 '16 at 16:54
0

I just found the solution to change the color of the background of TextArea in JavaFX. Write this in your controller class:

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

I was deep searching on the stackoverflow and eventually found it. The link is given below: Textarea javaFx Color

Happy coding!