add Style Sheet to JavaFX Scene - Java JavaFX

Java examples for JavaFX:Scene

Description

add Style Sheet to JavaFX Scene

Demo Code


import java.io.InputStream;
import java.util.logging.Logger;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;

public class Main{
    public static void addStyleSheet(Class<?> clazz, Scene scene,
            String resourceName) {

        if (clazz == null || scene == null || resourceName == null
                || resourceName.isEmpty()) {
            return;
        }/*from w ww  .ja  v  a 2 s  .c o  m*/

        try {
            scene.getStylesheets().add(
                    clazz.getResource(resourceName).toExternalForm());

        } catch (NullPointerException e) {
            System.err.println("CSS resource not found: " + resourceName);

        }

    }
}

Related Tutorials