btnOpenNewWindow.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { Parent root; try { root = FXMLLoader.load(getClass().getClassLoader().getResource("path/to/other/view.fxml"), resources); Stage stage = new Stage(); stage.setTitle("My New Stage Title"); stage.setScene(new Scene(root, 450, 450)); stage.show(); // Hide this current window (if this is what you want) ((Node)(event.getSource())).getScene().getWindow().hide(); } catch (IOException e) { e.printStackTrace(); } } }
@Override public void start(final Stage stage) throws Exception { StackPane pane = new StackPane(); JFXSpinner root = new JFXSpinner(); pane.getChildren().add(root); final Scene scene = new Scene(pane, 300, 300); scene.getStylesheets().add(MainDemo.class.getResource("/css/jfoenix-components.css").toExternalForm()); stage.setScene(scene); stage.setTitle("JFX Spinner Demo"); stage.show(); }
new Label("500: Aug 8, 12:15pm"), new Label("404: Aug 7, 3:27am") ).build(); Label nErrors = new Label(); nErrors.getStyleClass().add("nerrors"); nErrors.textProperty().bind(Bindings.size(errorPane.getChildren()).asString()); layout.setPrefHeight(150); layout.getStylesheets().add(this.getClass().getResource("titledpanecustomization.css").toExternalForm()); primaryStage.setScene(new Scene(layout)); primaryStage.show();
private Stage createEditPropertyDialog() { EditPropertyDialogController wizard = new EditPropertyDialogController(); FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("edit-property-dialog.fxml")); loader.setController(wizard); final Stage dialog = new Stage(); dialog.initOwner(this.getScene().getWindow()); dialog.initModality(Modality.WINDOW_MODAL); dialog.initStyle(StageStyle.UNDECORATED); Parent root; try { root = loader.load(); } catch (IOException e) { throw new IllegalStateException(e); } Scene scene = new Scene(root); dialog.setTitle("Edit property"); dialog.setScene(scene); dialog.setUserData(wizard); return dialog; }
public class Test extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { StackPane root = new StackPane(); root.setId("pane"); Scene scene = new Scene(root, 300, 250); scene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); } }
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.Stage; // displays the width in pixels of an arbitrary piece of text. public class MeasureText extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { final Text text = new Text("XYZZY"); new Scene(new Group(text)); // java 7 => // text.snapshot(null, null); // java 8 => text.applyCss(); final double width = text.getLayoutBounds().getWidth(); stage.setScene(new Scene(new Label(Double.toString(width)))); stage.show(); } }
imageView.setFitWidth(228); final Label label = new Label("The Once\nand\nFuture King"); label.setStyle("-fx-text-fill: goldenrod; -fx-font: italic 20 \"serif\"; -fx-padding: 0 0 20 0; -fx-text-alignment: center"); layout.getChildren().addAll(imageView, glass); layout.setStyle("-fx-background-color: silver; -fx-padding: 10;"); stage.setScene(new Scene(layout)); stage.show();
import javafx.application.Application; import javafx.scene.*; import javafx.scene.media.*; import javafx.stage.Stage; public class VideoPlayerExample extends Application { public static void main(String[] args) throws Exception { launch(args); } @Override public void start(final Stage stage) throws Exception { final MediaPlayer oracleVid = new MediaPlayer( new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv") ); stage.setScene(new Scene(new Group(new MediaView(oracleVid)), 540, 208)); stage.show(); oracleVid.play(); } }
private void clickShow(ActionEvent event) { Stage stage = new Stage(); Parent root = FXMLLoader.load( YourClassController.class.getResource("YourClass.fxml")); stage.setScene(new Scene(root)); stage.setTitle("My modal window"); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner( ((Node)event.getSource()).getScene().getWindow() ); stage.show(); }
Button configure = new Button("Configure"); changeBackgroundOnHoverUsingBinding(configure); Button update = new Button("Update"); changeBackgroundOnHoverUsingEvents(update); layout.setStyle("-fx-padding: 10;"); layout.getChildren().addAll(configure, update); stage.setScene(new Scene(layout)); stage.show();
@Override public Parent loadAsModal(String name) { final Stage mainStage = requireNonNull(userInterfaceComponent.getStage()); final Stage dialog = new Stage(); final Parent root = (Parent) load(name); final Scene scene = new Scene(root); BrandUtil.applyBrandToScene(injector, scene); dialog.setTitle("About " + infoComponent.getTitle()); dialog.initModality(APPLICATION_MODAL); brand.logoSmall().map(Image::new).ifPresent(dialog.getIcons()::add); dialog.initOwner(mainStage); dialog.setScene(scene); dialog.show(); return root; } }
root.getChildren().addAll(new TreeItem<>("Layout"), new TreeItem<>("is not"), new TreeItem<>("easy")); TreeView<String> notes = new TreeView<>(root); optionPane.getChildren().addAll(menuBar, new Label("Kaiser Notes"), notes); optionPane.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;"); layout.setLeft(optionPane); layout.setCenter(editorBox); stage.setScene(new Scene(layout)); stage.show();
@Override public void start(Stage primaryStage) throws Exception { JFXToolbar jfxToolbar = new JFXToolbar(); jfxToolbar.setLeftItems(new Label("Left")); jfxToolbar.setRightItems(new Label("Right")); StackPane main = new StackPane(); main.getChildren().add(jfxToolbar); Scene scene = new Scene(main, 600, 400); scene.getStylesheets().add(ToolBarDemo.class.getResource("/css/jfoenix-components.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); }
try{ FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Demo.fxml")); Parent root1 = (Parent) fxmlLoader.load(); Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); stage.initStyle(StageStyle.UNDECORATED); stage.setTitle("ABC"); stage.setScene(new Scene(root1)); stage.show(); }
public void start(Stage primaryStage) { Button btn = new Button("Say 'Hello World'"); AnchorPane root = new AnchorPane(); root.getChildren().add(btn); // Java 8: requires setting the layout pane background style to transparent // https://javafx-jira.kenai.com/browse/RT-38938 // "Modena uses a non-transparent background by default" root.setStyle("-fx-background-color: transparent;"); Scene scene = new Scene(root, 300, 250, Color.TRANSPARENT); primaryStage.initStyle(StageStyle.TRANSPARENT); primaryStage.setScene(scene); primaryStage.show(); }
public void show() { dialog.setOpacity(0); // pickerDecorator.setOpacity(0); if (dialog.getOwner() != null) { dialog.widthProperty().addListener(positionAdjuster); dialog.heightProperty().addListener(positionAdjuster); positionAdjuster.invalidated(null); } if (dialog.getScene() == null) { dialog.setScene(customScene); } curvedColorPicker.preAnimate(); dialog.show(); if (initOnce) { initRun.run(); initOnce = false; } Timeline timeline = new Timeline(new KeyFrame(Duration.millis(120), new KeyValue(dialog.opacityProperty(), 1, Interpolator.EASE_BOTH))); timeline.setOnFinished((finish) -> curvedColorPicker.animate()); timeline.play(); }