2017-07-18 27 views
-1

我在我的JavaFX應用程序中有一個ChoiceDialog,而且對於我來說,無法弄清楚需要更改CSS樣式的外觀和感覺。我的其他對話框窗格似乎受到我的外部CSS文件的影響,所以我猜測它是我不熟悉的元素。JavaFX ChoiceDialog CSS

此外,這將是重寫模式的CSS。

我曾嘗試:

.dialog-pane { 
-fx-background-color: black; 
} 

.dialog-pane .label { 
-fx-text-fill: white; 
} 

.dialog-pane:header .header-panel { 
-fx-background-color: black; 
} 

.dialog-pane:header .header-panel .label { 
-fx-font-style: italic; 
-fx-font-size: 2em; 
} 

我也試過:

.choice-dialog .dialog-pane { 
-fx-background-color: black; 
} 

.choice-dialog .dialog-pane .label { 
-fx-text-fill: white; 
} 

.choice-dialog .dialog-pane:header .header-panel { 
-fx-background-color: black; 
} 

.choice-dialog .dialog-pane:header .header-panel .label { 
-fx-font-style: italic; 
-fx-font-size: 2em; 
} 

以及那些2(.choice-對話框& .dialog窗格)的其他幾個變種 另一件事我試過(在查看modena.css文件後)是通過執行以下操作更改顯示在ChoiceDialog中的圖標:

from

.choice-dialog.dialog-pane { 
-fx-graphic: url("dialog-confirm.png"); 
} 

.choice-dialog.dialog-pane { 
-fx-graphic: url("dialog-warning.png"); 
} 

雖然這沒有結果無論是。

UPDATE

我更新了自定義的CSS文件,刪除了一切,重試上述的CSS。 CSS的第一塊只改變DialogPane,而不是ChoiceDialog。第二個和第三個什麼也沒做。

這裏是我用來創建ChoiceDialog

ChoiceDialog<String> dialog = new ChoiceDialog<>("district", choices); 
dialog.setTitle("Object Selection"); 
dialog.setHeaderText("Which object should the file inherit from?"); 
dialog.setContentText("Default Object:"); 

Stage dialogStage = (Stage) dialog.getDialogPane().getScene().getWindow(); 
dialogStage.getIcons().add(icon); 
dialogStage.initOwner(stage); 

Optional<String> response = dialog.showAndWait(); 
response.ifPresent(chosen -> 
{ 
    //It does something... 
}); 

ChoiceDialog

Dialog<ObservableList<DataFilter>> dialog = new Dialog<>(); 
dialog.getDialogPane().setPrefSize(620, 430); 
dialog.setTitle("Field Filter"); 
dialog.getDialogPane().getButtonTypes().addAll(save_bt, cancel_bt); 
dialog.initOwner(stage); 
dialog.setResultConverter((ButtonType b) -> 
{ 
    if (b == save_bt) 
    { 
     return FXCollections.observableArrayList(dataFilters); 
    } 
    return null; 
}); 

Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow(); 
stage.getIcons().add(icon); 

DialogPane

+0

您可以詳細介紹一下嗎?你想要應用什麼樣的風格,以及你爲了應用它而實際嘗試過什麼?發佈[MCVE]。 –

+0

已更新,以顯示我所嘗試的內容。 –

+0

您是否嘗試過'.choice-dialog.dialog-pane'(如您在modena.css中發佈的代碼片段中所示,沒有空格),而不是'.choice-dialog .dialog-pane'(帶空格)? 'url(...)'函數將查找相對於CSS文件的圖像文件,所以除非你有一個代碼片段不能工作。如果這些修補程序不起作用,我建議您發佈[MCVE]。 –

回答

0

我花了實驗一小時的代碼。其他幾個選擇器在modena.css中的「缺省列表視圖爲基礎的組合框」下。

.dialog-pane{ 
-fx-background-color: #7160DC; 
    } 
.dialog-pane > *.button-bar > *.container{ 
-fx-background-color: #7160DC; 
    } 
    .dialog-pane > .content .label{ 
    -fx-font-size: 15px; 
    -fx-font-weight: bold; 
    -fx-text-fill: orange; 
    } 
    .dialog-pane:header .header-panel{ 
    -fx-background-color: #9589DF; 
    } 
    .dialog-pane:header .header-panel .label{ 
    -fx-font-size: 18px; 
    -fx-font-style: italic; 
    } 

    .button{ 
    -fx-background-color:black; 
    -fx-text-fill:white; 
    } 

    .button:hover{  
    -fx-background-color:orange; 
    -fx-text-fill:black; 
    -fx-font-weight:bold; 
    } 

    /* styles background of cover choice*/ 
    .combo-box { 
    -fx-background-color: black; 
    -fx-font-weight: bold; 
    } 
    /* styles text of cover choice*/ 
    .combo-box > .list-cell { 
    -fx-text-fill: yellow; 
    } 

.combo-box-popup > .list-view { 
-fx-background-color:black; 
-fx-background-insets: 0, 1; 
-fx-effect: dropshadow(gaussian , rgba(0,0,0,0.2) , 12, 0.0 , 0 , 8); 
} 

.combo-box-popup > .list-view > .virtual-flow > .clipped-container > .sheet > .list-cell { 
-fx-padding: 4 0 4 5; 
-fx-background: black; 
} 

.combo-box-popup > .list-view > .virtual-flow > .clipped-container > .sheet 
> .list-cell:filled:hover { 
-fx-background-color: orange; 
-fx-text-fill: black; 
} 

//add the above .css file as stylesheet 

ChoiceDialog dialog = new ChoiceDialog(); 
    dialog.setTitle("Confirmation"); 
    dialog.setContentText("Some Text"); 
    DialogPane dp = dialog.getDialogPane(); 
    dp.getStylesheets().add(getClass().getResource("myCssFile.css") 
    .toExternalForm()); 
    Optional<String> result = dialog.showAndWait(); 
+0

那是什麼?它如何回答這個問題?它有什麼作用? https://stackoverflow.com/help/how-to-answer – Rob

+0

這是一個.css文件,並回答了「如何設計ChoiceDialog風格」的問題?它將樣式表作爲樣式表添加到ChoiceDialog後進行樣式設置。我將通過代碼更新答案如何添加樣式表。 – Helmwag

+0

不是我的觀點。我的觀點是你不應該只是在沒有解釋的情況下脫口而出。沒有人從中學習。 – Rob