2016-04-25 104 views
0

我正在使用Popover,它用作Textfield的工具提示类帮助显示。 它包含一个Label和TextArea作为内容,并在用户输入文本字段时创建。 (通过FocusPropery.addListenerControlsfx PopOver风格和焦点

我申请使用样式:

popOver.getRoot().getStylesheets().add(...) 

该方法适用于文本区域(如文档documentation中发现的),但只为partialy标签。

我的风格是这样的:

*{ 
    -tb-dark-grey: rgb(32,38,44); 
} 

.root { 
    -fx-base: -tb-dark-grey; 
    -fx-background: -tb-dark-grey; 
    -fx-control-inner-background: -tb-dark-grey; 
} 

这在我的主窗口的工作非常好。包括所有标签和TextAreas。一切都会得到一个带有白色文字的深蓝色背景。 但对于Popover中的标签,仅将文本颜色更改为白色,但背景保持通常的浅灰色。

我尝试使用TextArea作为解决方法。这适用于风格。但它始终窃取文本字段的重点。这使得键入内容变得不可能。禁用TextArea的作品,但改变了TextArea的风格。

我已经尝试应用在this other question中找到的样式。 我也尝试让重点回来,这也没有工作。

popup.Show(this.inputField) 
this.inputField.requestFocus(); // also tried this with Platform.runLater 

回答

0

你的问题应该是Label不使用任何你已经在你的.root样式类覆盖的颜色。根据JavaFX CSS reference guide,您可以使用fx-background-color来设置Label的背景。

添加下面一行到你的样式表应该做的伎俩:

.label { 
    -fx-background-color: -tb-dark-grey; 
} 

您也可以单独通过创建自定义样式类,如果你想以不同的风格标签应用的样式为每个标签

CSS:

.custom-label { 
    -fx-background-color: -tb-dark-grey; 
} 

然后将它应用到一个特定的标签:

Label label = new Label("I am a label"); 
label.getStyleClass().add("custom-label"); 

编辑:您应该知道,您的TextArea将不会显示您在样式表中定义的确切颜色。如果您检查Modena样式表,这是JavaFX的默认主题和样式(如何找到它,请参阅here)。您可以在TextArea内容中找到以下css:

.text-area .content { 
    /*the is 1px less top and bottom than TextInput because of scrollpane border */ 
    -fx-padding: 0.25em 0.583em 0.25em 0.583em; /* 3 7 3 7 */ 
    -fx-cursor: text; 
    -fx-background-color: 
     linear-gradient(from 0px 0px to 0px 4px, derive(-fx-control-inner-background, -8%), -fx-control-inner-background); 
    -fx-background-radius: 2; 
} 

正如您所看到的。 TextArea内容的背景颜色并不完全是您在样式表中定义的-fx-control-inner-background,而是从-fx-control-inner-background派生的颜色变为所需颜色的线性渐变。这可能对你而言并不明显,但可能很好理解。

设置TextArea背景的颜色,以便它是你的恰恰可能颜色像这样做:

.text-area .content { 
    -fx-background-color: tb-dark-grey; 
} 
+0

作品。这基本上是我最终使用的解决方案。我不喜欢明确剥皮标签的想法。作为更通用的解决方案,我编写了一个辅助类来创建弹出窗口,将所需内容包装到VBox中,并将我的基本颜色作为背景应用于VBox。 'vBox.setStyle(“ - fx-background-color:-tb-skin-base;”);'这种方式适用于所有可能的上下文形式,不仅适用于Label。这使我的CSS更清洁。也谢谢指出TextArea的颜色。 – FrankT