Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 682837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:38:27+00:00 2026-05-14T01:38:27+00:00

I have applied CSS style to JavaFX components and it looks like everything is

  • 0

I have applied CSS style to JavaFX components and it looks like everything is working fine except one situation: when I add JavaFX components to component tree on-the-fly their CSS styles are not applied.

For example following code:

package test;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.input.MouseEvent;
import javafx.util.Math;
import javafx.scene.paint.Color;

function getRect(): Rectangle {
    return Rectangle {
        x: 230 * Math.random()
        y: 60 * Math.random()
        width: 20, height: 20
        styleClass: "abc"
    }
}

def stage: Stage = Stage {
    scene: Scene {
        width: 250, height: 80
        stylesheets: "{__DIR__}main.css"
        content: [
            Rectangle {
                x: 0, y: 0, width: 250, height: 80
                fill: Color.WHITE
                onMouseClicked: function (evt: MouseEvent): Void {
                    insert getRect() into stage.scene.content;
                }
            }
            getRect()
        ]
    }
}

with following stylesheet:

.abc {
    fill: red;
}

in main.css file (both in test package) display red square on white background, but after clicking the main rectangle black (not red) squares are added to scene.

I noticed that:

  1. Components added dynamically look just like style information was not applied.
  2. If you set their style in JavaFX code then everything works fine.
  3. After changing stylesheets property (so that it points to another valid stylesheet) the objects already added render properly.

Does anyone know the solution to this problem? I could of course put all the properties into JavaFX code or provide another stylesheet (for every existing stylesheed) that would contain the same data and change stylesheet right after adding any component, but I would like to find some elegant solution.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:38:27+00:00Added an answer on May 14, 2026 at 1:38 am

    It’s a bug in 1.2. It is fixed in the next release.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have a css style like this : input.validation-passed {border: 1px solid
Let's say we have defined a CSS class that is being applied to various
I have a filter attribute that I'd like to be applied to every action
I have the following CSS style code for my table: table { table-layout: fixed;
In the root of my domain i have the CSS file style.css and the
I have an HTML as following: <html> <head> <style type=text/css> a {color: red} </style>
I have applied a Formatter to a JFormattedTextField using a FormatterFactory , when a
When have you ever directly applied the concepts of dynamic programming to solve a
I'm trying to set a CSS style using .live(). The CSS function: $(.data tr:odd).addClass(evenrows);
I have created a CSS class as follows: div.ycontent div.ppclisting { background-color:#cccccc; } div.ycontent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.