Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle css resources declared as classpath resource #13

Open
McFoggy opened this issue Nov 13, 2014 · 1 comment
Open

handle css resources declared as classpath resource #13

McFoggy opened this issue Nov 13, 2014 · 1 comment

Comments

@McFoggy
Copy link
Owner

McFoggy commented Nov 13, 2014

People reported me they were using CSS like

scene.getStylesheets().add("/styles/main.css")

instead of using a URL.

The JavaFX CSS reference guide says that CSS should be referenced by URL.

Not clear yet if we have to support it or not.

@mkpaz
Copy link

mkpaz commented Apr 8, 2022

I'm not sure why it's not implemented. Imo, placing plain CSS file to the app classpath, namely target/classes, is the simplest and most obvious way to play with theming your app. No need to build JAR and no need to install it to local Maven repo. But CSSFX has no built-in converter to handle simple file urls. Anyway, it's easy enough to create one:

URIToPathConverter fileUrlConverter = uri -> {
    try {
        if (uri != null && uri.startsWith("file:")) {
            return Paths.get(URI.create(uri));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
};

CSSFX.addConverter(fileUrlConverter).start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants