Skip to main content

Where to Place External CSS File

The following is what a lot of tutorials recommend to specify the CSS file in JavaFX

scene.getStylesheets().add("myStyle.css");

But where do you place the "myStyle.css" file?

A JavaFX project typically is located as follows (using Netbeans):

C:\Users\UserName\Documents\NetBeansProjects\JavaFXProjectFolder

Insider the project folder, you will find the following:


Don't place your CSS file in "src" which is where many tutorial tell you to place the CSS file. You will loose your hair prematurely  due to excessive scratching as you try to convince your app to find your CSS.

Instead, open the "build" folder inside which you will find:

Place your CSS file in the "classes" folder that contains compiled Java classes. It will look like this:

Best wishes with you JavaFXing.

Comments

Post a Comment

Popular posts from this blog

LAMBDA EXPRESSIONS FOR HANDLING EVENTS

Event handlers form the core of any application. They define what happens when you click a button, press a key, select a menu and so on. The discussion on this site demonstrates how to use Lambda expressions to handle events. It is elegant and greatly simplifies your code. The old way of handling a button-click looks like this: Button btn = new Button(); btn.setText("Say 'Hello World'");  btn.setOnAction(new EventHandler<ActionEvent>() {       @Override       public void handle(ActionEvent event)       {           System.out.println("Hello World!");       }  }); The following is a Lambda expression using a "goes to" operator (->): Button button = new Button("Click"); button.setOnAction(value -> { label.setText("Clicked!"); }); Even more elegant: someButton.setOnAction(evt -> someM...

How to Run JavaFX 11+ in Intellij IDEA

First published: 8th June 2019 This page explains: 1. How to set up Intellij IDEA with JavaFX 11+ 2. How to configure Intellij IDEA to run JavaFX programs. Follow the links below to download the guides: 1. JavaFX 1 - Installing IntelliJ IDEA and JavaFX 11 Tutorial (8-6-19) 2.  Configure Intellij IDEA to run JavaFX programs

Sane JavaFX GUI Code

JavaFX GUI Sanity JavaFX GUI code can be quite chaotic. Such a situation makes it a challenge to understand the code and to troubleshoot it.  JavaFX GUIs are simple in concept but if you try hard enough, you can disorganise it. Disorganised code is a sign of confusion which is a sign of deeper malaise.... JavaFX graphic user interfaces can be built up very systematically by following a simple process: All the GUI is contained in a Stage . This Stage constitutes the visible application window though it does not have to be visible. On this stage is placed a Scene which contains Panes to organise and hold GUI controls such as buttons and text boxes. However, bad programming practice allows a programmer to add controls directly to the Scene . The problem with this practice is that there is no way to lay out such controls in a systematic pattern such as horizontal list or in a grid formation. Each Scene can have zero, one or more Panes . Panes can contain other Panes ...