javafx textarea背景颜色不是css [英] javafx textarea background color not css

查看:486
本文介绍了javafx textarea背景颜色不是css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在SceneBuilder中更改textarea的背景颜色。

我没有在样式菜单中更改:-fx-background-color。

所以我发现使用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;
}

但我想改变除css文件之外的其他方式。
请给我一个提示。

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

推荐答案

您可以在Java代码中更改它:

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" );
}

要做到这一点,我们首先查找孩子 Region 文本区域的子结构然后在其上应用样式。这个动作应该在舞台出现后完成。

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.

这篇关于javafx textarea背景颜色不是css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆