2016-04-25 81 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