I tried all the methods written in the stackoverflow, but all these methods did not work for me.
These are the methods I tried:
- Javafx WARNING: Resource "style.css" not found intellij
- https://www.dreamincode.net/forums/topic/406296-resource-stylecss-not-found/
- https://blog.idrsolutions.com/2014/04/use-external-css-files-javafx/
- https://coderoad.ru/22627579/%D0%9A%D0%B0%D0%BA-%D0%B7%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%B8%D1%82%D1%8C-%D1%84%D0%B0%D0%B9%D0%BB-css-%D0%B2-javafx8
Everything works well in the scene builder, but when I run the program, this comes out:
nove. 01, 2021 9:10:50 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
INFO: Could not find stylesheet:
file:/C:/Users/User/Desktop/Coursework/AppLibrary/target/classes/com/example/applibrary/style.css
nove. 01, 2021 9:10:50 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "src/main/resources/styles.css" not found.
My code looks like this:
package com.example.applibrary;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("login.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1000, 500);
//
scene.getStylesheets().add("src/main/resources/styles.css");
//
stage.setResizable(false);
stage.setTitle("Login");
stage.setScene(scene);
stage.centerOnScreen();
stage.show();
}
public static void main(String[] args) {
launch();
}
}
My folders look like this:
- src
- main
- java
- resources
- style.css
- main