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

  • SEARCH
  • Home
  • 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 9249061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:05:54+00:00 2026-06-18T10:05:54+00:00

In HTML we are used to niceties of being able to set stylesheets programmatically

  • 0

In HTML we are used to niceties of being able to set stylesheets programmatically like

<link rel="stylesheet" ... >

But the examples of setting stylesheets I found for JavaFX require setting stylesheets programmatically, like

scene.getStylesheets().add("/resources/shell.css");

Is it possible to set stylesheets in FXML similar to the way it is done in HTML?

  • 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-06-18T10:05:55+00:00Added an answer on June 18, 2026 at 10:05 am

    You can set stylesheets on Parent nodes using:

    parent.getStylesheets().add("/resources/shell.css");
    

    Because the elements and attributes usable in FXML are derived from the public JavaFX Java API, then you can also assign stylesheets to a Parent node using an FXML stylesheets element (or interchangeably an attribute). As all containers extend Parent, you can set one or more custom stylesheets on any container you reference in FXML:

    <?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.layout.*?>
    <?import java.net.URL?>
       ....
    <?scenebuilder-stylesheet fruitcombo.css?>
    
    <AnchorPane prefHeight="205.0" prefWidth="168.0"
       styleClass="layout"
       fx:controller="fruit.FruitComboController"
       xmlns:fx="http://javafx.com/fxml">
       <children>
          ....
       </children>
       <stylesheets>
          <URL value="@fruitcombo.css" />
       </stylesheets>
    </AnchorPane>
    

    See the fxml file in this sample for a complete executable sample of referencing a css file from an fxml file.

    There are a couple of nice to have features in the above code:

    The strange @ prefix in the stylesheets URL isn’t strictly needed, but can be used to take advantage of JavaFX’s location resolution. “The location resolution operator (represented by an “@” prefix to the attribute value) is used to specify that an attribute value should be treated as a location relative to the current file rather than a simple string.”

    The following line isn’t required at runtime, but is used by the SceneBuilder tool to locate the required css stylesheet at design time if you are using that tool:

    <?scenebuilder-stylesheet fruitcombo.css?>
    

    Update regarding the comment

    Warning: It’s FXML 1.0, it’s not working in 2.0, javafx.fxml.LoadException: URL is not a valid type.

    This comment is a bit incorrect I think. As far as I am aware, there is no such thing currently as FXML 2.0.

    The reason the commenter received a LoadException was because the indicative snippet in this post was not importing the the java.net.URL class into the FXML document. I updated the snippet to include the java.net.URL import and add some more ellipsis .... to clarify the intent of the snippet. An ellipsis means “a series of dots that usually indicates an intentional omission of a word, sentence, or whole section from a text without altering its original meaning”.

    To best understand this answer it is suggested to compile and run the linked sample code.

    Warning against using InputStream load functions in FXMLLoader

    I strongly advise constructing an new FXMLLoader with a location, rather than using the FXMLLoader.load(InputStream) function. When the static load() function is used, then relative location references cannot be resolved as there is no base location for the FXML file.

    I.e., don’t do:

     InputStream input = this.getClass().getResourceAsStream("layout.fxml");
     FXMLLoader loader = new FXMLLoader.load(input);
     Parent content = loader.load();
    

    Instead do:

     String url = this.getClass().getResource("layout.fxml").toExternalForm();
     FXMLLoader loader = new FXMLLoader(url);
     Parent content = loader.load();  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the examples here: http://api.jquery.com/append/ they show straight HTML being used as an argument:
html() should be used for setting content in non-form elements such as div's. **
I want to display image in TextView with text, I had used Html.ImageGetter but
I could have used @Html.HiddenFor(x=> ViewData[crn]) but, I get, <input id=ViewData_crn_ name=ViewData[crn] type=hidden value=500
I have following code on http://septicsecurity.com/facebook.html It used to work, but does not work
What does <!DOCTYPE> describe other than the version of HTML being used and if
How would I link identical HTML used in several pages, instead of adding the
I have used HTML 5 audio tags like the following <audio controls=control_2> <source src=D:\HND_grrrrr\Year_2\RoyWebsite\Sounds\WAV\home_page_readout.wav
I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
I am mostly following this page: http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html I used this command to create the

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.