Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a dark mode with JavaFx

I was wondering if there is an easy way to make a dark mode using JavaFx and CSS. I have a MenuBar with a CheckMenuItem called 'Dark mode' and when I click it I want the scene to become dark and the text to become white.

like image 866
Sander B Avatar asked Mar 07 '18 18:03

Sander B


People also ask

How do you change the color of the background in JavaFX?

The simplest way to set the JavaFX Scene background color or image is by invoking the Scene 's setFill() method, which can accept a color, gradient or image pattern. A more flexible way to set the background of a scene is to set the root node's background, which can accept multiple images and fills.

How can you change the JavaFX theme used in your layout?

You can change the JavaFX theme used in your layout by selecting Preview from the Menu bar and selecting one of the JavaFX themes, as shown in Figure 11-1. From the drop-down list you can select a Modena-based theme specific for your target platform.

Can you use CSS in JavaFX?

This topic describes how to use cascading style sheets (CSS) with JavaFX applications. Use CSS to create a custom look for your application. Style sheets contain style definitions that control the look of user interface elements. Using CSS in JavaFX applications is similar to using CSS in HTML.


1 Answers

Here's mine.

(Update) The previous one was too opaque.

.root { 
    -fx-accent: #1e74c6;
    -fx-focus-color: -fx-accent;
    -fx-base: #373e43;
    -fx-control-inner-background: derive(-fx-base, 35%);
    -fx-control-inner-background-alt: -fx-control-inner-background ;
}

.label{
    -fx-text-fill: lightgray;
}

.text-field {
    -fx-prompt-text-fill: gray;
}

.titulo{
    -fx-font-weight: bold;
    -fx-font-size: 18px;
}

.button{
    -fx-focus-traversable: false;
}

.button:hover{
    -fx-text-fill: white;
}

.separator *.line { 
    -fx-background-color: #3C3C3C;
    -fx-border-style: solid;
    -fx-border-width: 1px;
}

.scroll-bar{
    -fx-background-color: derive(-fx-base,45%)
}

.button:default {
    -fx-base: -fx-accent ;
} 

.table-view{
    /*-fx-background-color: derive(-fx-base, 10%);*/
    -fx-selection-bar-non-focused: derive(-fx-base, 50%);
}

.table-view .column-header .label{
    -fx-alignment: CENTER_LEFT;
    -fx-font-weight: none;
}

.list-cell:even,
.list-cell:odd,
.table-row-cell:even,
.table-row-cell:odd{    
    -fx-control-inner-background: derive(-fx-base, 15%);
}

.list-cell:empty,
.table-row-cell:empty {
    -fx-background-color: transparent;
}

.list-cell,
.table-row-cell{
    -fx-border-color: transparent;
    -fx-table-cell-border-color:transparent;
}

enter image description here

like image 84
Wesos de Queso Avatar answered Sep 30 '22 12:09

Wesos de Queso