Java Code Examples for javafx.stage.Stage#setScene()

The following examples show how to use javafx.stage.Stage#setScene() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminController.java    From HealthPlus with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
@FXML
public void showSuccessIndicator()
{
    Stage stage= new Stage();
    SuccessIndicatorController success = new SuccessIndicatorController();
    Scene scene = new Scene(success);
    stage.setScene(scene);
    
    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
    //set Stage boundaries to visible bounds of the main screen
    stage.setX(primaryScreenBounds.getMinX());
    stage.setY(primaryScreenBounds.getMinY());
    stage.setWidth(primaryScreenBounds.getWidth());
    stage.setHeight(primaryScreenBounds.getHeight());
    
    stage.initStyle(StageStyle.UNDECORATED);
    scene.setFill(null);
    stage.initStyle(StageStyle.TRANSPARENT);
    stage.show();
}
 
Example 2
Source File: TesterApplication.java    From OEE-Designer with MIT License 6 votes vote down vote up
public void start(Stage primaryStage) {
	try {
		FXMLLoader loader = FXMLLoaderFactory.testerApplicationLoader();
		AnchorPane mainLayout = loader.getRoot();
		
		testerController = loader.getController();
		testerController.initialize();

		Scene scene = new Scene(mainLayout);

		primaryStage.setTitle(TesterLocalizer.instance().getLangString("test.app.title"));
		primaryStage.getIcons().add(ImageManager.instance().getImage(Images.POINT85));
		primaryStage.setScene(scene);
		primaryStage.show();
	} catch (Exception e) {
		logger.error(e.getMessage());
		stop();
	}
}
 
Example 3
Source File: Game2048.java    From fx2048 with GNU General Public License v3.0 5 votes vote down vote up
private void setGameBounds(Stage primaryStage, Scene scene) {
    var margin = UserSettings.MARGIN;
    var gameBounds = gamePane.getGameManager().getLayoutBounds();
    var visualBounds = Screen.getPrimary().getVisualBounds();
    double factor = Math.min(visualBounds.getWidth() / (gameBounds.getWidth() + margin),
            visualBounds.getHeight() / (gameBounds.getHeight() + margin));
    primaryStage.setTitle("2048FX");
    primaryStage.setScene(scene);
    primaryStage.setMinWidth(gameBounds.getWidth() / 2d);
    primaryStage.setMinHeight(gameBounds.getHeight() / 2d);
    primaryStage.setWidth(((gameBounds.getWidth() + margin) * factor) / 1.5d);
    primaryStage.setHeight(((gameBounds.getHeight() + margin) * factor) / 1.5d);
}
 
Example 4
Source File: MusicPlayer.java    From MusicPlayer with MIT License 5 votes vote down vote up
private static void createLibraryXML() {
    try {
        FXMLLoader loader = new FXMLLoader(MusicPlayer.class.getResource(Resources.FXML + "ImportMusicDialog.fxml"));
        BorderPane importView = loader.load();

        // Create the dialog Stage.
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Music Player Configuration");
        // Forces user to focus on dialog.
        dialogStage.initModality(Modality.WINDOW_MODAL);
        // Sets minimal decorations for dialog.
        dialogStage.initStyle(StageStyle.UTILITY);
        // Prevents the alert from being re-sizable.
        dialogStage.setResizable(false);
        dialogStage.initOwner(stage);

        // Sets the import music dialog scene in the stage.
        dialogStage.setScene(new Scene(importView));

        // Set the dialog into the controller.
        ImportMusicDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);

        // Show the dialog and wait until the user closes it.
        dialogStage.showAndWait();

        // Checks if the music was imported successfully. Closes the application otherwise.
        boolean musicImported = controller.isMusicImported();
        if (!musicImported) {
            System.exit(0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: Loading.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void startMainApp(Stage ms) {
    try {
        long time = System.currentTimeMillis();
        Stage stage = new Stage();
        stage.setTitle(Undecorator.LOC.getString("AppName") + " " + Undecorator.LOC.getString("Version") + " 版本号:" + Undecorator.LOC.getString("VersionCode"));
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
        Region root = (Region) fxmlLoader.load();
        final UndecoratorScene undecoratorScene = new UndecoratorScene(stage, root);
        stage.setOnCloseRequest((WindowEvent we) -> {
            we.consume();
            undecoratorScene.setFadeOutTransition();
        });
        undecoratorScene.getStylesheets().add("/styles/main.css");
        stage.setScene(undecoratorScene);
        stage.toFront();
        stage.getIcons().add(new Image(getClass().getResourceAsStream("/skin/icon.png")));
        stage.setOnShown((event) -> {
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    Platform.runLater(() -> {
                        ms.close();
                    });
                }
            }, 1000);
        });
        stage.show();
        ApplicationStageManager.putStageAndController(ApplicationStageManager.StateAndController.MAIN, stage, fxmlLoader.getController());
        LOGGER.info("主页面加载耗时:" + (System.currentTimeMillis() - time) + "毫秒");
    } catch (IOException ex) {
        LOGGER.error("启动主程序异常", ex);
    }
}
 
Example 6
Source File: Demo3dViewer.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception
{
    Viewer3dPane viewerPane = new Viewer3dPane(null, null);
    
    Scene scene = new Scene(viewerPane, 1000, 1000);
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 7
Source File: ScatterChartDemo.java    From Java-9-Cookbook with MIT License 5 votes vote down vote up
@Override
public void start(Stage stage) throws IOException {

	GridPane gridPane = new GridPane();
	gridPane.setAlignment(Pos.CENTER);
	gridPane.setHgap(10);
	gridPane.setVgap(10);
	gridPane.setPadding(new Insets(25, 25, 25, 25));

	Map<String, List<FallOfWicket>> fow = getFallOfWickets();

	final NumberAxis xAxis = new NumberAxis();
       final NumberAxis yAxis = new NumberAxis();
       xAxis.setLabel("Age");
       yAxis.setLabel("Marks");
       final ScatterChart<Number,Number> scatterChart = 
           new ScatterChart<>(xAxis,yAxis);
       scatterChart.getData().add(getSeries(
       	fow.get("NZ"),
       	"NZ"
       ));
       scatterChart.getData().add(getSeries(
       	fow.get("IND"),
       	"IND"
       ));
       
	gridPane.add(scatterChart, 1, 1);
	
	Scene scene = new Scene(gridPane, 600, 400);
	stage.setTitle("Bubble Charts");
	stage.setScene(scene);
	stage.show();
}
 
Example 8
Source File: NumberSpinnerDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("JavaFX Spinner Demo");
    GridPane root = new GridPane();
    root.setHgap(10);
    root.setVgap(10);
    root.setPadding(new Insets(10, 10, 10, 10));
    final NumberSpinner defaultSpinner = new NumberSpinner();
    final NumberSpinner decimalFormat = new NumberSpinner(BigDecimal.ZERO, new BigDecimal("0.05"), new DecimalFormat("#,##0.00"));
    final NumberSpinner percent = new NumberSpinner(BigDecimal.ZERO, new BigDecimal("0.01"), NumberFormat.getPercentInstance());
    final NumberSpinner localizedCurrency = new NumberSpinner(BigDecimal.ZERO, new BigDecimal("0.01"), NumberFormat.getCurrencyInstance(Locale.UK));
    root.addRow(1, new Label("default"), defaultSpinner);
    root.addRow(2, new Label("custom decimal format"), decimalFormat);
    root.addRow(3, new Label("percent"), percent);
    root.addRow(4, new Label("localized currency"), localizedCurrency);
    Button button = new Button("Dump layout bounds");
    button.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent arg0) {
            defaultSpinner.dumpSizes();
        }
    });
    root.addRow(5, new Label(), button);

    Scene scene = new Scene(root);
    //String path = NumberSpinnerDemo.class.getResource("/fxui/css/spinner/number_spinner.css").toExternalForm();
    String path = "/fxui/css/spinner/number_spinner.css";
    System.out.println("path = " + path);
    //scene.getStylesheets().add(path);
    scene.getStylesheets().add(getClass().getResource(path).toExternalForm());
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 9
Source File: RingProgressIndicatorExample.java    From fx-progress-circle with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) {
	RingProgressIndicator indicator = new RingProgressIndicator();
	Slider slider = new Slider(0, 100, 50);

	slider.valueProperty().addListener((o, oldVal, newVal) -> indicator.setProgress(newVal.intValue()));
	VBox main = new VBox(1, indicator, slider);
	indicator.setProgress(Double.valueOf(slider.getValue()).intValue());
	Scene scene = new Scene(main);
	primaryStage.setScene(scene);
	primaryStage.setTitle("Test ring progress");
	primaryStage.show();

}
 
Example 10
Source File: ParetoTest.java    From charts with Apache License 2.0 5 votes vote down vote up
@Override public void start(Stage stage) {

        PresentationPareto pres = new PresentationPareto();
        init();
        StackPane pane  = new StackPane(pres);
        Scene     scene = new Scene(pane);


        stage.setTitle("Pareto Chart");
        stage.setScene(scene);
        stage.setWidth(1200);
        stage.show();
    }
 
Example 11
Source File: KeyStrokeMotion.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setResizable(false);
    primaryStage.setScene(new Scene(root, 480,480));
    lettersPane = new LettersPane();
    root.getChildren().add(lettersPane);
}
 
Example 12
Source File: CategoryMarkerFXDemo1.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    StackPane sp = new StackPane();
    sp.getChildren().add(createDemoNode());
    Scene scene = new Scene(sp, 768, 512);
    stage.setScene(scene);
    stage.setTitle("Orson Charts: CategoryMarkerFXDemo1.java");
    stage.show();
}
 
Example 13
Source File: TextFieldTreeTableSampleApp.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("TreeTable View Sample");
    primaryStage.setScene(new Scene(new TextFieldTreeTableSample()));
    primaryStage.sizeToScene();
    primaryStage.show();
    TreeTableView<?> treeTableView = (TreeTableView<?>) primaryStage.getScene().getRoot().lookup(".tree-table-view");
    treeTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
}
 
Example 14
Source File: Exercise_14_15.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create a stack pane
	StackPane stackPane = new StackPane();

	// Create a polygon and set its properties
	Polygon polygon = new Polygon();
	stackPane.getChildren().add(polygon);
	polygon.setFill(Color.RED);
	polygon.setRotate(20);
	ObservableList<Double> list = polygon.getPoints();

	final double WIDTH = 200, HEIGHT = 200;
	double centerX = WIDTH / 2, centerY = HEIGHT / 2;
	double radius = Math.min(WIDTH, HEIGHT) * 0.4;

	// Add points to polygon list
	for (int i = 0; i < 8; i++) {
	 	list.add(centerX + radius * Math.cos(2 * i * Math.PI / 8));
	 	list.add(centerY - radius * Math.sin(2 * i * Math.PI / 8));
	}

	// Create a text and set its properties
	Text text = new Text("STOP");
	text.setFont(Font.font("Times new Roman", FontWeight.BOLD, 40));
	text.setFill(Color.WHITE);
	stackPane.getChildren().add(text);

	// Create a scene and place it in the stage
	Scene scene = new Scene(stackPane, WIDTH, HEIGHT);
	primaryStage.setTitle("Exercise_14_15"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 15
Source File: LoginController.java    From Online-Food-Ordering-System with MIT License 5 votes vote down vote up
@FXML
    public void MenuScreen(ActionEvent event) throws Exception  {
	Stage primaryStage =new Stage();
	Parent root =FXMLLoader.load(getClass().getResource("Menu.fxml"));
               primaryStage.setTitle("Welcome To Foody Menu");
	Scene scene = new Scene(root);
	primaryStage.setScene(scene);
	primaryStage.show();
               
           // Hide this current window (if this is what you want)
           ((Node)(event.getSource())).getScene().getWindow().hide();
}
 
Example 16
Source File: BubbleChartDemo.java    From Java-11-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Override
public void start(Stage stage) throws IOException {

	GridPane gridPane = new GridPane();
	gridPane.setAlignment(Pos.CENTER);
	gridPane.setHgap(10);
	gridPane.setVgap(10);
	gridPane.setPadding(new Insets(25, 25, 25, 25));

	final NumberAxis xAxis = new NumberAxis();
       final NumberAxis yAxis = new NumberAxis();
       xAxis.setLabel("Hour");
       yAxis.setLabel("Visits");
       final BubbleChart<Number,Number> bubbleChart = 
           new BubbleChart<>(xAxis,yAxis);

      	List<StoreVisit> data = getData();
      	Integer maxSale = getMaxSale(data);
	XYChart.Series<Number,Number>  series = new XYChart.Series<>();
	series.setName("Store Visits");
	data.forEach(sv -> {
		series.getData().add(new XYChart.Data<Number, Number>(
       		sv.hour, sv.visits, (sv.sales/(maxSale  * 1d)) * 2
       	));
	});

	bubbleChart.getData().add(series);
	gridPane.add(bubbleChart, 1, 1);
	
	Scene scene = new Scene(gridPane, 600, 400);
	stage.setTitle("Bubble Charts");
	stage.setScene(scene);
	stage.show();
}
 
Example 17
Source File: ColorPickerApp.java    From oim-fx with MIT License 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setScene(new Scene(createContent()));
    primaryStage.show();
}
 
Example 18
Source File: DisplayWFSLayerSample.java    From arcgis-runtime-samples-java with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {

  // create stack pane and JavaFX app scene
  StackPane stackPane = new StackPane();
  Scene scene = new Scene(stackPane);

  // set title, size, and add JavaFX scene to stage
  stage.setTitle("Display a WFS Layer");
  stage.setWidth(800);
  stage.setHeight(700);
  stage.setScene(scene);
  stage.show();

  // create an ArcGISMap with topographic basemap and set it to the map view
  ArcGISMap map = new ArcGISMap(Basemap.createTopographic());
  mapView = new MapView();
  mapView.setMap(map);

  // create an initial extent to load
  Point topLeft = new Point(-13619002.499764, 6043406.351867);
  Point bottomRight = new Point(-13618454.919189, 6042836.793464);
  Envelope initialExtent = new Envelope(topLeft, bottomRight);
  mapView.setViewpoint(new Viewpoint(initialExtent));

  String serviceUrl = "https://dservices2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/services/Seattle_Downtown_Features/WFSServer?service=wfs&request=getcapabilities";
  String LayerName = "Seattle_Downtown_Features:Buildings";

  // create a FeatureTable from the WFS service URL and name of the layer
  WfsFeatureTable wfsFeatureTable = new WfsFeatureTable(serviceUrl, LayerName);

  // set the feature request mode to manual. The table must be manually populated as panning and zooming won't request features automatically.
  wfsFeatureTable.setFeatureRequestMode(ServiceFeatureTable.FeatureRequestMode.MANUAL_CACHE);

  // create a feature layer to visualize the WFS features
  FeatureLayer wfsFeatureLayer = new FeatureLayer(wfsFeatureTable);

  // apply a renderer to the feature layer
  SimpleRenderer renderer = new SimpleRenderer(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFFFF0000, 3));
  wfsFeatureLayer.setRenderer(renderer);

  // add the layer to the map's operational layers
  map.getOperationalLayers().add(wfsFeatureLayer);

  // make an initial call to load the initial extent's data from the WFS, using the WFS spatial reference
  populateFeaturesFromServer(wfsFeatureTable, initialExtent);

  // use the navigation completed event to populate the table with the features needed for the current extent
  mapView.addNavigationChangedListener(navigationChangedEvent -> {
    // once the map view has stopped navigating
    if (!navigationChangedEvent.isNavigating()) {
      populateFeaturesFromServer(wfsFeatureTable, mapView.getVisibleArea().getExtent());
    }
  });

  // add the mapview to the stackpane
  stackPane.getChildren().add(mapView);
}
 
Example 19
Source File: Overlay1App.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

    Parent p = FXMLLoader.load(getClass().getResource("/overlay1-fxml/Overlay1.fxml"));

    final double rem = Font.getDefault().getSize();

    Scene scene = new Scene(p);

    scene.getStylesheets().add("/css/overlay1.css");

    primaryStage.setScene(scene);
    primaryStage.initStyle(StageStyle.TRANSPARENT);
    primaryStage.show();

}
 
Example 20
Source File: FxWebViewExample2.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(final Stage stage)
{
	// Create the WebView
	WebView webView = new WebView();

	// Disable the context menu
	webView.setContextMenuEnabled(false);

	// Increase the text font size by 20%
	webView.setFontScale(1.20);

	// Set the Zoom 20%
	webView.setZoom(1.20);

	// Set font smoothing type to GRAY
	webView.setFontSmoothingType(FontSmoothingType.GRAY);

	// Create the WebEngine
	final WebEngine webEngine = webView.getEngine();
	// Load the StartPage
	webEngine.load("http://www.google.com");

	// Update the stage title when a new web page title is available
	webEngine.titleProperty().addListener(new ChangeListener<String>()
	{
	    public void changed(ObservableValue<? extends String> ov,
	            final String oldvalue, final String newvalue)
	    {
	    	stage.setTitle(newvalue);
	    }
	});

	// Create the VBox
	VBox root = new VBox();
	// Add the Children to the VBox
	root.getChildren().add(webView);

	// Set the Style-properties of the VBox
	root.setStyle("-fx-padding: 10;" +
			"-fx-border-style: solid inside;" +
			"-fx-border-width: 2;" +
			"-fx-border-insets: 5;" +
			"-fx-border-radius: 5;" +
			"-fx-border-color: blue;");

	// Create the Scene
	Scene scene = new Scene(root);
	// Add  the Scene to the Stage
	stage.setScene(scene);
	// Display the Stage
	stage.show();
}