javafx textarea background color not css

天涯浪子 提交于 2019-12-14 02:18:12

问题


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 .


回答1:


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.



来源:https://stackoverflow.com/questions/29745413/javafx-textarea-background-color-not-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!