jake
jake

Reputation: 679

javafx textarea background color not css

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 .

Upvotes: 3

Views: 10621

Answers (2)

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!

Upvotes: 1

Uluk Biy
Uluk Biy

Reputation: 49215

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.

Upvotes: 6

Related Questions