JavaFX How to change color of dialog/window title?

Tags: css,colors,javafx,dialog,title

Problem :

since yesterday, i'm trying to change the color of my dialog title (or maybe all title colors of my application) to get a black or dark color, because it's white color and not readable with grey background.

I still think it should work with css but i can't really find the specific entry for the title color.

I tried something like this in dialog.css but did not work, so commented out:

.root {     
-fx-text-base-color: blue;
-fx-text-background-color: green;
-fx-text-inner-color: red;
-fx-selection-bar-text: yellow;

Here my Dialog class:

package de.test.dialog;


import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class Dialog extends Stage {

public static final String OK_DIALOG = "OK";

private final String OK_XML = "/fxml/dialog_ok.fxml";

public enum DIALOG_ACTION {

private DialogController controller = null;
private String message = null;

public Dialog(String name, String ... buttonName) {     
    String resource = getFXMLResource(name);
    if (resource != null) {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(resource));
            Parent root = (Parent) fxmlLoader.load();
            controller = fxmlLoader.getController();
            setScene(new Scene(root));
        catch (IOException e) {

    setOnCloseRequest(new EventHandler<WindowEvent>() {
        public void handle(WindowEvent event) {

private String getFXMLResource(String name) {
    String fxmlResource = null;

    switch(name) {
        case OK_DIALOG:
            fxmlResource = OK_XML;

    return fxmlResource;

public Dialog.DIALOG_ACTION getAction() {
    if (controller != null) {
        return controller.getAction();
    else {

public void setMessage(String sMessage) {
    this.message = sMessage;
    if (controller != null) {

public void setIcon(Image image) {      
    if (controller != null) {

Dialog fxml:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="176.0" prefWidth="400.0" stylesheets="@styles/dialog.css" xmlns="" xmlns:fx="" fx:controller="de.test.dialog.DialogController">
  <ImageView fx:id="imgIcon" fitHeight="48.0" fitWidth="48.0" layoutX="8.0" layoutY="25.0" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="15.0" AnchorPane.topAnchor="25.0">
        <Image url="@../icons/dialog/48a.png" />
  <Text fx:id="txtMessage" layoutX="85.0" layoutY="45.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TEST" wrappingWidth="300.00" AnchorPane.leftAnchor="94.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="25.0">
        <Font size="14.0" />
  <Button fx:id="btn1" defaultButton="true" layoutX="295.0" layoutY="134.0" mnemonicParsing="false" onAction="#doAction" prefHeight="25.0" prefWidth="90.0" text="OK" AnchorPane.rightAnchor="15.0">
        <Font size="14.0" />
  <Button fx:id="btn2" cancelButton="true" layoutX="180.0" layoutY="134.0" mnemonicParsing="false" onAction="#doAction" prefHeight="25.0" prefWidth="90.0" text="Abbrechen" visible="false" AnchorPane.rightAnchor="120.0">
        <Font size="14.0" />
  <Button fx:id="btn3" layoutX="102.0" layoutY="134.0" mnemonicParsing="false" onAction="#doAction" prefHeight="25.0" prefWidth="90.0" text="Button 3" visible="false" AnchorPane.rightAnchor="225.0">
        <Font size="14.0" />

Calling my dialog:

    Dialog dialog = new Dialog(Dialog.OK_DIALOG, "Löschen", "Abbrechen");
    dialog.setTitle("Dateianhang löschen");     
    dialog.setMessage("Wollen Sie die ausgewählte(n) Datei(en) wirklich löschen?");

    // Get the Stage.
    //Stage stage = (Stage) dialog.getScene().getWindow();
    // Add a custom icon.
    //stage.getIcons().add(new Image("/icons/dialog/48a.png"));


As you can see, i tried to change the title icon (commented out), and that worked. But no chance to change the color of the title.

If i try google whith e.g. javafx, i can see a lot of images with black title colors. So it must be possible to change the color, but i don't know how.

Any suggestions?

Greetings, Tom

Solution :

I stand to be corrected but I don't think you can set the color of the NATIVE title bar. I think what you are seeing in the google results are custom (user) made title bars.

Maybe this link is useful to you:

You can also have a look at the FXControls Dialogs source code and see how they have done it:

    CSS Howto..

    How to shift a background image with css

    Show warnings screen resolution

    how to make a div to wrap two float divs inside?

    How to handle text overflow. Is there a Firefox equivalent to the text-overflow style from IE and Safari?

    How to evenly distribute menu items with CSS when width and quantity is not known?

    How can I instantly stop a CSS animation on hover?

    How to send CSS to the client using HTTP response headers?

    How to style first paragraph

    of the content differently without using css class , ID or javascript, with IE6 compatibility?

    Codeigniter shows views differently when index is removed

    How to prevent line breaks in list items using CSS

    How can I make two divs stack whilst still having my text wrap without media queries

    Inheriting CSS how do I stop it?

    less: how to import multiple css?

    How to center my images in my case?

    How can I use themeroller'ed styles in “regular” parts of a page?

    HTML/CSS: How to make a bar on the side to take you to a certain part of the page

    How can I animate this?

    WordPress admin stylesheet not showing images

    How to fire a new css animation when the element already has one?

    slide show with bootstrap

    how do i change the css property for only one row with a custom class with out removing the styles from the other rows?

    css how to force to ul,ol to show numbers or disc, after reset the list style.?

    CSS: How to get lines to “line up” accross different columns?

    How to Change Default Bootstrap Fluid Grid 12 Column Gutter Width

    How to add new fonts in CSS for local testing

    How to get the click position on a page when a css zoom is involved

    How to stop people from viewing my HTML and CSS [closed]

    How to keep a navbar toggle open until selection is made

    How can I target text input fields with CSS?

    How to style button inputs to be identical in Chrome and Firefox?