2016-11-22 60 views
1

我有这样的代码:文本的CSS样式没有出现白色

private void createAndAddCommonInformationSection(){ 
    Text text = new Text("CommonText"); 
    gridPane.add(header); 
} 

的应该会出现在白色的颜色,所以我有一个CCS文件如下:

.root { 
-fx-base: rgb(50, 50, 50); 
-fx-background: rgb(50, 50, 50); 
-fx-control-inner-background: rgb(50, 50, 50); 
} 

.tab { 
-fx-background-color: linear-gradient(to top, -fx-base, derive(-fx-base,30%)); 
} 

.menu-bar { 
-fx-background-color: linear-gradient(to bottom, -fx-base, derive(-fx-base,30%)); 
} 

.tool-bar:horizontal { 
-fx-background-color: 
linear-gradient(to bottom, derive(-fx-base,+50%), derive(-fx-base,-40%), derive(-fx-base,-20%)); 
} 

.button { 
-fx-background-color: transparent; 
} 

.button:hover { 
-fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color; 
-fx-color: -fx-hover-base; 
} 

.table-view { 
-fx-table-cell-border-color:derive(-fx-base,+10%); 
-fx-table-header-border-color:derive(-fx-base,+20%); 
} 

.split-pane:horizontal > * > .split-pane-divider { 
-fx-border-color: transparent -fx-base transparent -fx-base; 
-fx-background-color: transparent, derive(-fx-base,20%); 
-fx-background-insets: 0, 0 1 0 1; 
} 

.my-gridpane { 
-fx-background-color: radial-gradient(radius 100%, derive(-fx-base,20%), derive(-fx-base,-20%)); 
} 

.separator-label { 
-fx-text-fill: orange; 
} 

.text{ 
-fx-text-fill: white; 
} 

一切都很是使用CSS文件工作正常,除了我的代码段中的文本颜色不会以预期的颜色显示。

我已经尝试

-fx-fill: white; 

-fx-fill-text: white; 

,但没有什么帮助。

我在做什么错?

+0

@Rinin猜测这与问题中的'javafx'有关。 – sevenseacat

+0

@Rounin阅读[文档](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#intronaming):“命名惯例已经建立用于派生JavaFX类名称中的CSS样式类名称以及从JavaFX变量名称派生CSS属性名称......将JavaFX变量名称映射到CSS属性名称的约定与添加'-fx-'前缀相似。 “ –

回答

0

根据documentationText节点没有默认样式类。所以你需要

text.getStyleClass().add("text"); 

为了让文本节点匹配CSS选择器。然后

.text { 
    -fx-fill: white ; 
} 

将工作。

通常,如果你想用CSS样式它,虽然手动添加的样式类到Text节点应该工作,你会使用一个Labelfx-text-fill财产一起。

+0

我希望避免将所有内容都改为标签(这是现有的代码 - 不是我自己的代码)。出于某种原因,此代码根本不使用任何标签。 :( – Marco

+0

@Marco这听起来很有趣...我会让你评估是否更容易手动添加一堆样式类,或者将所有'Text'实例更改为'Label's ... –

+0

什么是混乱!在代码本身中有一些样式,CSS做了一些样式,我想我会在今天关闭Eclipse并重新思考这个问题以找到一个合适的解决方案,不管他做了什么,他都不知道他在做什么,假设。 – Marco