javafx textarea background color not css

javafx, scenebuilder, textarea

Solution

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.

Problem

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 .

Original source

Related problems