【问题标题】:javafx textarea background color not cssjavafx textarea背景颜色不是css
【发布时间】:2015-04-20 10:31:32
【问题描述】:

我想更改 SceneBuilder 中 textarea 的背景颜色。
我未能更改样式菜单:-fx-background-color。
于是我发现使用CSS文件来改变背景颜色。

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

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

【问题讨论】:

  • CSS 是推荐的方法。为什么不想使用它?
  • @James_D 目前,在我的项目中,我需要更改代码。有办法吗?

标签: javafx textarea scenebuilder


【解决方案1】:

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

@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 子结构,然后对其应用样式。此操作应在舞台显示后执行。

【讨论】:

  • 谢谢。是否可以使用textarea的setstyle?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
  • 2014-01-15
  • 2012-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多