2014-10-09 37 views
0

我對JavaFX上下文中的CSS並不十分了解。 我試圖訪問一些TitledPanes的標籤,所以我可以把一個簡單的圖像旁邊的標籤,但我無法弄清楚什麼是適當的語法是這樣做的。我需要使用什麼CSS語法來訪問JavaFX中TitledPane的標籤?

我已經試過:

.TitledPane > .title > .text { //TitledPane is the CSS class I assign to my Title Panes. 
    /*CSS Code Here*/ 
} 

這沒有奏效。

.TitledPane > .title { } //This only affects the background, I would like the graphic to be side-by-side with the actual text. 

.TitlePane LabeledText { } //This worked with Buttons so I thought it might work with TitledPane. I was wrong. 

我需要使用什麼來訪問標籤才能使用CSS來設置它的樣式?

+0

此無關的HTML。這是JavaFX。 JavaFX控件可以使用CSS樣式表來指定它們的樣式。 – Will 2014-10-09 17:06:02

+1

你需要css嗎?爲什麼不在Java代碼(或FXML中的等價物)中執行'myTitledPane.setGraphic(...)'? – 2014-10-09 17:15:58

+0

是的,我知道這是一個選項,但如果可以在CSS中做,我寧願保持Java代碼相對簡潔。這是最後的手段。 – Will 2014-10-09 17:29:21

回答

1

CSS documentation for TitledPane似乎是錯誤的:標題中的text類實際解析爲Text對象,而不是Label,如前所述。當然,Text不支持-fx-graphic css屬性。

幸運的是,因爲TitledPane擴展Labeled,你可以只使用在Labeled直接定義屬性:

.TitledPane { 
    -fx-graphic: url(path/to/image/file) ; 
} 
+0

你是男人。這正是我所看到的,謝謝。 – Will 2014-10-09 18:14:29

相關問題