I am new to javafx and am trying to connect my class to my CSS file however when I use:
scene.getStylesheets().add("Viper.css");
I get the following warning:
Dec 08, 2016 9:12:54 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "Viper.css" not found.
But when I use:
scene.getStylesheets().add(getClass().getResource("/resources/CSS/Viper.css").toExternalForm());
I get an InvocationTargetException
Here is my entire class and I am positive that the filepath is correct. I am using NetBeans IDE.
package com.GUI;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class window extends Application{
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("OmegaBrain");
//Create Panes
Pane titlePane = new Pane();
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Text sceneTitle = new Text("Welcome To OmegaBrain");
sceneTitle.setFont(Font.font("Helvetica", FontWeight.NORMAL, 20));
grid.add(sceneTitle, 0, 0, 4, 1);
Scene scene = new Scene(grid, 300, 275);
scene.getStylesheets().add("/resources/CSS/Viper.css");
primaryStage.setScene(scene);
primaryStage.show();
Button play = new Button("Play");
grid.add(play, 1, 1);
Button leaderboard = new Button("Leaderboard");
grid.add(leaderboard, 2, 1);
Button faq = new Button("FAQs");
grid.add(faq, 3, 1);
Button exit = new Button("Exit");
grid.add(exit, 4, 1);
play.setOnAction((ActionEvent e) -> {
System.out.println("The play button was clicked!");
});
}
public static void main(String[]args){
launch(args);
}
}