Example usage for javafx.scene Scene getStylesheets

List of usage examples for javafx.scene Scene getStylesheets

Introduction

In this page you can find the example usage for javafx.scene Scene getStylesheets.

Prototype

public final ObservableList<String> getStylesheets() 

Source Link

Document

Gets an observable list of string URLs linking to the stylesheets to use with this scene's contents.

Usage

From source file:TwoButtons.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final RowLayout layout = new RowLayout();
    shell.setLayout(layout);/*w  w w .j  a  v a  2 s  . c  om*/

    /* Create the SWT button */
    final org.eclipse.swt.widgets.Button swtButton =
            new org.eclipse.swt.widgets.Button(shell, SWT.PUSH);
    swtButton.setText("SWT Button");

    /* Create an FXCanvas */
    final FXCanvas fxCanvas = new FXCanvas(shell, SWT.NONE) {

        public Point computeSize(int wHint, int hHint, boolean changed) {
            getScene().getWindow().sizeToScene();
            int width = (int) getScene().getWidth();
            int height = (int) getScene().getHeight();
            return new Point(width, height);
        }
    };
    /* Create a JavaFX Group node */
    Group group = new Group();
    /* Create a JavaFX button */
    final Button jfxButton = new Button("JFX Button");
    /* Assign the CSS ID ipad-dark-grey */
    jfxButton.setId("ipad-dark-grey");
    /* Add the button as a child of the Group node */
    group.getChildren().add(jfxButton);
    /* Create the Scene instance and set the group node as root */
    Scene scene = new Scene(group, Color.rgb(shell.getBackground().getRed(), shell.getBackground().getGreen(),
            shell.getBackground().getBlue()));
    /* Attach an external stylesheet */
    scene.getStylesheets().add("twobuttons/Buttons.css");
    fxCanvas.setScene(scene);

    /* Add Listeners */
    swtButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            jfxButton.setText("JFX Button: Hello from SWT");
            shell.layout();
        }
    });
    jfxButton.setOnAction(new EventHandler<ActionEvent>() {

        public void handle(ActionEvent event) {
            swtButton.setText("SWT Button: Hello from JFX");
            shell.layout();
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:kz.aksay.polygraph.desktop.DesignerWorkFlow.java

@Override
public void start(final Stage primaryStage) {

    context = kz.aksay.polygraph.util.ContextUtils.getApplicationContext();
    context.getBean(UserService.class);
    acaContext = new AnnotationConfigApplicationContext();
    acaContext.setParent(context);//from   w  w  w  .j a v  a  2 s .  c om
    acaContext.scan("kz.aksay.polygraph.desktop");
    acaContext.refresh();

    LoginPane loginPane = acaContext.getBean(LoginPane.class);

    Scene scene = new Scene(loginPane, 480, 320);
    scene.getStylesheets().add(DesignerWorkFlow.class.getResource("login.css").toExternalForm());

    loginPane.setOnSignInSuccess(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            DirectorPane directorPane = acaContext.getBean(DirectorPane.class);
            Scene scene = new Scene(directorPane, 640, 480);
            primaryStage.setScene(scene);
        }
    });

    primaryStage.setScene(scene);
    primaryStage.setTitle("JavaFX Welcome");
    primaryStage.show();
}

From source file:com.exalttech.trex.ui.UIBaseTest.java

@Override
public void start(Stage stage) throws Exception {
    TrexApp.setPrimaryStage(stage);//from  www .j  a  v a 2s . c om
    AnchorPane page = (AnchorPane) FXMLLoader.load(getClass().getResource("/fxml/MainView.fxml"));
    Scene scene = new Scene(page);
    scene.getStylesheets().add(TrexApp.class.getResource("/styles/mainStyle.css").toExternalForm());
    stage.setScene(scene);
    stage.setTitle("TRex");
    stage.setResizable(true);
    stage.setMinWidth(1100);
    stage.setMinHeight(670);
    stage.show();
}

From source file:org.pdfsam.ui.info.InfoStage.java

@Inject
public InfoStage(InfoPane infoPane, Collection<Image> logos, StylesConfig styles) {
    BorderPane containerPane = new BorderPane();
    containerPane.getStyleClass().addAll(Style.CONTAINER.css());
    containerPane.setCenter(infoPane);/*  ww w.  j  av a 2  s  . co  m*/
    containerPane.setBottom(new ClosePane());
    Scene scene = new Scene(containerPane);
    scene.getStylesheets().addAll(styles.styles());
    scene.setOnKeyReleased(new HideOnEscapeHandler(this));
    setScene(scene);
    setTitle(DefaultI18nContext.getInstance().i18n("Document details"));
    getIcons().addAll(logos);
    setMaximized(true);
}

From source file:org.pdfsam.App.java

@Override
public void start(Stage primaryStage) {
    STOPWATCH.start();/*  w w w  . ja  v a  2  s.  co m*/
    LOG.info(DefaultI18nContext.getInstance().i18n("Starting pdfsam"));
    List<String> styles = (List<String>) ApplicationContextHolder.getContext().getBean("styles");
    Map<String, Image> logos = ApplicationContextHolder.getContext().getBeansOfType(Image.class);
    MainPane mainPane = ApplicationContextHolder.getContext().getBean(MainPane.class);

    NotificationsContainer notifications = ApplicationContextHolder.getContext()
            .getBean(NotificationsContainer.class);
    StackPane main = new StackPane();
    StackPane.setAlignment(notifications, Pos.BOTTOM_RIGHT);
    StackPane.setAlignment(mainPane, Pos.TOP_LEFT);
    main.getChildren().addAll(mainPane, notifications);

    Scene scene = new Scene(main);
    scene.getStylesheets().addAll(styles);
    primaryStage.setScene(scene);
    primaryStage.getIcons().addAll(logos.values());
    primaryStage.setTitle(ApplicationContextHolder.getContext().getBean("appName", String.class));
    scene.getAccelerators().put(new KeyCodeCombination(KeyCode.L, KeyCombination.SHORTCUT_DOWN),
            () -> eventStudio().broadcast(new ShowStageRequest(), "LogStage"));
    primaryStage.show();
    eventStudio().add(new TitleController(primaryStage));
    requestCheckForUpdateIfNecessary();
    eventStudio().addAnnotatedListeners(this);
    STOPWATCH.stop();
    LOG.info(DefaultI18nContext.getInstance().i18n("Started in {0}",
            DurationFormatUtils.formatDurationWords(STOPWATCH.getTime(), true, true)));
}

From source file:org.pdfsam.ui.dialog.OverwriteConfirmationDialog.java

@Inject
public OverwriteConfirmationDialog(StylesConfig styles) {
    initModality(Modality.WINDOW_MODAL);
    initStyle(StageStyle.UTILITY);/*from ww  w  .ja  va2  s  .c o m*/
    setResizable(false);
    BorderPane containerPane = new BorderPane();
    containerPane.getStyleClass().addAll(Style.CONTAINER.css());
    containerPane.getStyleClass().addAll("-pdfsam-dialog", "-pdfsam-warning-dialog");
    containerPane.setCenter(dialogContent);
    HBox buttons = new HBox(buildButton(DefaultI18nContext.getInstance().i18n("Overwrite"), true),
            buildButton(DefaultI18nContext.getInstance().i18n("Cancel"), false));
    buttons.getStyleClass().add("-pdfsam-dialog-buttons");
    containerPane.setBottom(buttons);
    Scene scene = new Scene(containerPane);
    scene.getStylesheets().addAll(styles.styles());
    scene.setOnKeyReleased(new HideOnEscapeHandler(this));
    setScene(scene);
}

From source file:org.dataconservancy.packaging.gui.App.java

public void start(Stage stage) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath*:org/dataconservancy/config/applicationContext.xml",
            "classpath*:org/dataconservancy/packaging/tool/ser/config/applicationContext.xml",
            "classpath*:applicationContext.xml");

    // min supported size is 800x600
    stage.setMinWidth(800);/* w w w. j a v a 2 s  .  com*/
    stage.setMinHeight(550);
    Factory factory = (Factory) context.getBean("factory");
    factory.setStage(stage);

    Font.loadFont(App.class.getResource("/fonts/OpenSans-Regular.ttf").toExternalForm(), 14);
    Font.loadFont(App.class.getResource("/fonts/OpenSans-Italic.ttf").toExternalForm(), 14);
    Font.loadFont(App.class.getResource("/fonts/OpenSans-Bold.ttf").toExternalForm(), 14);

    Configuration config = factory.getConfiguration();
    CmdLineParser parser = new CmdLineParser(config);

    try {
        List<String> raw = getParameters().getRaw();
        parser.parseArgument(raw.toArray(new String[raw.size()]));
    } catch (CmdLineException e) {
        System.out.println(e.getMessage());
        log.error(e.getMessage());
        Platform.exit();
        return;
    }

    Controller controller = factory.getController();
    controller.setApplicationHostServices(getHostServices());

    controller.startApp();

    // Default size to 800x800, but shrink if screen is too small
    double sceneHeight = 800;

    Rectangle2D screen = Screen.getPrimary().getVisualBounds();
    if (screen.getHeight() < 800) {
        sceneHeight = screen.getHeight() - 50;
        if (sceneHeight < 550)
            sceneHeight = 550;
    }

    Scene scene = new Scene(controller.asParent(), 800, sceneHeight);
    scene.getStylesheets().add("/css/app.css");

    stage.getIcons().add(new Image("/images/DCPackageTool-icon.png"));
    stage.setTitle("DC Package Tool");
    stage.setScene(scene);
    stage.show();

}

From source file:nl.rivm.cib.fx.HelloWorldJavaFX.java

@Override
public void start(final Stage stage) throws Exception {

    LOG.info("Starting Hello JavaFX and Maven demonstration application");

    String fxmlFile = "/fxml/hello.fxml";
    LOG.debug("Loading FXML for main view from: {}", fxmlFile);
    FXMLLoader loader = new FXMLLoader();
    Parent rootNode = (Parent) loader.load(getClass().getResourceAsStream(fxmlFile));

    LOG.debug("Showing JFX scene");
    Scene scene = new Scene(rootNode, 400, 200);
    scene.getStylesheets().add("/styles/styles.css");

    stage.setTitle("Hello JavaFX and Maven");
    stage.setScene(scene);//ww w  .j a v a  2 s . com
    stage.show();
}

From source file:net.noctuasource.noctua.core.ui.ExceptionDialog.java

protected ExceptionDialog(Exception exception) {
    this.exception = exception;

    VBox root = new VBox();

    stage = new Stage();
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setTitle("Exception");
    Scene scene = new Scene(root);
    scene.getStylesheets().add(getClass().getResource(CSS_FILE).toExternalForm());
    stage.setScene(scene);//from  w ww  .  j  a  v  a  2s.  c  om

    FXMLLoader loader = new FXMLLoader();
    loader.setClassLoader(getClass().getClassLoader());
    loader.setController(this);
    loader.setLocation(getClass().getResource(FXML_FILE));

    try {
        Node node = (Node) loader.load();
        root.getChildren().add(node);
        VBox.setVgrow(node, Priority.ALWAYS);
    } catch (IOException e) {
        logger.error("Error while creating view: ", e);
        stage.close();
        return;
    }

    messageField.setText(exception.getLocalizedMessage());
    fullExceptionField.setText(ExceptionUtils.getFullStackTrace(exception));

    //stage.sizeToScene();
    stage.centerOnScreen();
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    final GridPane grid = new GridPane();
    grid.setPadding(new Insets(10));
    grid.setHgap(10);//from  w  ww  .  j  a va2 s . c  o  m
    grid.setVgap(5);

    createControls(grid);
    createClipList(grid);

    final Scene scene = new Scene(grid, 640, 380);
    scene.getStylesheets().add(getClass().getResource("media.css").toString());

    primaryStage.setTitle("AudioClip Example");
    primaryStage.setScene(scene);
    primaryStage.show();
}