javafx textarea background color not css
Asked Answered
A

2

3

I want to change the background color of the textarea in SceneBuilder.
I failed to change in the style menu :-fx-background-color.
So I found to change the background color by using the CSS file.

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

But I want to change the other way except for the css file. Please give me a hint .

Arran answered 20/4, 2015 at 10:31 Comment(2)
CSS is the recommended approach. Why do you not want to use it?Daumier
@Daumier Currently , in my project , i will need to change to code . Is there a way ?Arran
L
6

You can change it in Java code:

@Override
public void start( Stage stage )
{
    TextArea area = new TextArea();
    Scene scene = new Scene( area, 800, 600 );
    stage.setScene( scene );
    stage.show();

    Region region = ( Region ) area.lookup( ".content" );
    region.setBackground( new Background( new BackgroundFill( Color.BROWN, CornerRadii.EMPTY, Insets.EMPTY ) ) );

    // Or you can set it by setStyle()
    region.setStyle( "-fx-background-color: yellow" );
}

To do that we first lookup the child Region sub structure of text area then apply styling on it. This action should be done after the stage has been shown.

Laminitis answered 20/4, 2015 at 11:48 Comment(1)
Thank you. Is it possible to use the setstyle of the textarea?Arran
R
1

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:#000000;");

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

Happy coding!

Rebellion answered 31/7, 2022 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.