0

here is a screenshoot of the hierarchy of my project :(https://i.stack.imgur.com/pY7uI.png)

here is the code source : StylingLoginPage.java:

package com.example.loginpage;

import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.geometry.Insets;
import javafx.scene.layout.GridPane;


import javafx.application.Application;

public class StylingLoginPage extends Application {

    public static void  main (String[] args){
        launch(args);
    }
    @Override
    public void start (Stage primaryStage){
        primaryStage.setTitle("CSS styling");

        //Name Label:
        Label namelabel = new Label("Username");
        GridPane.setConstraints(namelabel,0,0);

        //Username Input:
        TextField nameInput = new TextField();
        nameInput.setPromptText("Enter your name");
        GridPane.setConstraints(nameInput,1,0);

        //password Label:
        Label pwdlabel = new Label("password");
        GridPane.setConstraints(pwdlabel,0,1);

        //Password Input:
        TextField pwdInput = new TextField();
        pwdInput.setPromptText("Enter your password");
        GridPane.setConstraints(pwdInput,1,1);

        //Login Button:
        Button loginButton = new Button("Login");
        GridPane.setConstraints(loginButton ,1,2);

        //EventHandler:
        loginButton.setOnAction(e->System.out.println("User loged in .."));

        //Layout:
        GridPane gridpane = new GridPane();
        gridpane.setPadding(new Insets(10,10,10,10));
        gridpane.setVgap(10);
        gridpane.setHgap(10);
        gridpane.getChildren().addAll(namelabel,nameInput,pwdlabel,pwdInput,loginButton);

        //Scene:
        Scene scene = new Scene(gridpane,300,300);
        scene.getStylesheets().add("login-style.css");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

login-style.css

.root{
    -fx-background-color:#383838;
    -fx-font-size:11pt;
}

I'm building a login Page using javaFX and i tried to include some CSS style in my project . Wether i'm working on Eclipe or intellij IDEA, I'm getting the sam error: *com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged WARNING: Resource "login-style.css" not found. *

Woodchuck
  • 3,869
  • 2
  • 39
  • 70
  • 2
    You put the CSS file under the wrong directory. The `src/main/java` directory (and sub-directories, i.e., packages) are for `*.java` files only. Put CSS files, image files, FXML files, and other resources under the `src/main/resources` directory (or a sub-directory, i.e., package). – Slaw Apr 28 '23 at 19:00
  • 2
    And note `scene.getStylesheets().add("login-style.css")` will look for the resource at the **root** of the class-path. Make sure to specify the correct path; maybe use the `Class#getResource(String)` API. I recommend you read [How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?](https://stackoverflow.com/q/61531317/6395627) (which this question is probably a duplicate of). – Slaw Apr 28 '23 at 19:04

0 Answers0