Dynamically Modify Custom Style Class Properties in JavaFX Using CSS

Embarking on my CSS journey, I have limited experience since I mainly worked with JavaFX applications and not web languages. In one of my JavaFX applications, I utilized a css style sheet featuring a Windows 10 UWP theme. The default style classes adhere to the standard windows grey button theme, but I also implemented a custom style class for colored components.

The colors are defined as variables within the .root style class for the default style, and then overwritten in the .colored style class for the colored elements.

.root 
{
    -fill-color: #CCCCCC;
    ...
}

.colored
{
    -fill-color: #DD2867;
    ...
}

Now, I am faced with the challenge of changing the colors of the colored style dynamically at runtime. I'm familiar with Node#setStyle(String) which allows me to modify the fill color using code like this:

root.setStyle("-fill-color: #FF00FF;");

However, this only affects the color in the .root style class and not the .colored style class.

Is there a way to directly modify a property of a specific style class at runtime, or perhaps a better approach for managing both default and colored styles?

Thank you in advance, Eleom.

Answer №1

Introduce a new custom color variable on the root element, and incorporate it into your .colored class:

{
    -primary-color: #FFFFFF;
    -custom-color: #36BBA6 ;
    ...
}

.colored
{
    -primary-color: -custom-color;
    ...
}

You can then dynamically update that color in your code like this:

root.setStyle("-custom-color: ... ;");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Path to link to ms accdb file with reference to current file location

Currently working in NetBeans and this shows my project directory: https://i.sstatic.net/gUvwK.png The executable can be found in the 'dist' folder. As for the code, I have the following string in my connection class: "jdbc:ucanaccess://.&bsol ...

Tips for adjusting the color of the sidebar in an HTML email template

My attempt at modifying the background color of my HTML email template has been focused on changing the sidebar's white color, rather than altering the background of the email body itself. This is the CSS code I have: @import url('https://fonts. ...

What is the reason for the Client Height value not affecting other elements?

I'm trying to set the spacing of my sidebar from the top equal to the height of the header. However, when I use clientHeight in JavaScript to get the height and then try to apply it to other elements using marginTop or top values (with position includ ...

A single class designed to handle two distinct deserialization processes

Currently, I have a need to extract data from two separate websites and store it in a database. These websites provide data in a similar format, but with different JSON field names. I am aware that I cannot use more than one @JsonProperty annotation for a ...

Utilizing JQuery to create a dynamic background image slider that cycles through images extracted from a selection of

Case Study: Implementing a background-image slider with JQuery listening for window resizing. Depending on the screen size, a specific array is set as the image file paths source. Encountering a 6-second delay issue where the initial image does not displ ...

Troubleshooting the Selenium Protractor Webdriver-Manager Update Problem on Ubuntu

Upon running the webdriver-manager update command, I encountered the following error message. /usr/lib/node_modules/protractor/node_modules/webdriver-manager/built/lib/cmds/start.js:60 if (path.isAbsolute(options[Opt.OUT_DIR].getString())) { ...

Ways to monitor data usage for a specific network on an Android device

Is it possible to track data usage from a specific WiFi network on an Android device? I have tried searching for information on this but haven't found any answers. Can we accurately monitor how much data has been consumed on a network using an Android ...

Issues arising from incorporating a Vaadin view into a JSP application

In my Spring MVC application, I am using Vaadin along with JSP for login and registration forms. However, I am encountering an issue where the WebSecurity configuration may not be providing the POST method for my Vaadin view after a successful user authent ...

The picture is malfunctioning

I am experiencing an issue with the placement of an image in my HTML code. When I place the image inside the nav element, it works perfectly fine. However, when I try to put it inside the body or header elements, it doesn't display properly. I am new ...

``CSS: Styling a Rounded Div with a Clipped Scrollbar

I am attempting to contain a scrollbar within a div so that it remains within the rounded corners without overflowing. Take a look at the code snippet below to see the problem in action. Is there a way for the scrollbar to be fixed in its position, while ...

Locate the parent element that has the smallest amount of space taken up by its child elements

My goal is to determine which container, among several <divs>, each containing multiple child <divs> of varying sizes, has the smallest amount of space covered by the child elements. <div class="container" id="first"> ...

Instructions for utilizing a contract class within an Android application

I am feeling a bit perplexed as I try to decipher the tutorial located here: http://developer.android.com/training/basics/data-storage/databases.html#DbHelper Here is my current code: public final class DatabaseContract { // This empty constructor preven ...

Is there a way to retrieve all CSS styles associated with a specific element?

When I come across a site element that I really like and want to incorporate into my own site, what is a simple way to do so? It can be challenging to navigate through numerous CSS files to find all the necessary styles. ...

Modify the background color of <td> elements depending on the specific value

I attempted to implement this approach, but unfortunately it is not working as expected. I found guidance from this source. Below is the code I am using: $today = date('Y-m-d'); $date = new DateTime(); $R1D2 = $date->setISODate($year,$week,1 ...

How can CSS3 be used to target the initial or final visible element in a selection?

Looking to style form fieldsets with margins, while removing the margin-top for the first non-hidden fieldset and margin-bottom for the last non-hidden fieldset (any fieldset can be dynamically set as hidden by a script). I attempted the CSS below without ...

What is the best method for identifying an href element using Selenium webdriver in Java?

My testing page includes the following code: <a href="#sideMenu1756" data-toggle="collapse" class="parent list-group-item list-group-item-success"> Entrada de Operações <i aria-hidden="true" class="fa fa-chevron-right pull-right"></ ...

What is the most efficient way to transform Exif longitude and latitude into actual numerical values?

Seeking assistance with extracting Exif data from my photos, specifically the latitude and longitude values. I've received some numbers - DEBUG/lat = 30/1,12/1,34/1 (7588) : lattitude and DEBUG/long = 81/1,22/1,41/1 (7588) : longitude. Can someone pro ...

Creating a layout with Bootstrap 4 cards split into two rows

I need to change my layout from 3 columns to 2 columns. I know I can achieve this using CSS like the code snippet below, but I'm curious if there's a built-in Bootstrap method for this: .card-columns { -webkit-column-count: 2; -moz-column-co ...

Encountering a null JSON response while using Retrofit library

I am utilizing the Retrofit library to parse the JSON response from the TMDB API for the Now Playing Movies category and my goal is to showcase the outcomes in a RecyclerView. The raw JSON data I am receiving from the API is as follows: { "page": 1, ...

Is there a way to properly size and align an inline image within a dynamically resizing DIV element?

I am working on a fluid layout where I have a div that always matches the height and width of the browser window, regardless of resizing. Essentially, this div is set to be 100% height and width of the browser window. Inside this div, I have an image that ...