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

The following examples show how to use javafx.stage.Stage#setOnShown() . 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: TrafficProfileDialogController.java    From trex-stateless-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize current stage
 */
public void init() {
    currentStage = (Stage) profileViewWrapper.getScene().getWindow();

    currentStage.setOnShown(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            currentStage.focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue && tableView.isStreamEditingWindowOpen()) {
                    Util.optimizeMemory();
                    loadStreamTable();
                    tableView.setStreamEditingWindowOpen(false);
                }
            });
        }
    });
}
 
Example 2
Source File: DebugDialog.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public DebugDialog()
{
	GuiAssertions.assertIsJavaFXThread();
	FXMLLoader loader = new FXMLLoader();
	loader.setResources(LanguageBundle.getBundle());
	loader.setLocation(getClass().getResource("DebugDialog.fxml"));
	primaryStage = new Stage();
	final Scene scene;
	try
	{
		scene = loader.load();
	} catch (IOException e)
	{
		Logging.errorPrint("failed to load debugdialog", e);
		return;
	}
	primaryStage.setScene(scene);
	DebugDialogController controller = loader.getController();
	primaryStage.setOnShown(e -> controller.initTimer());
}
 
Example 3
Source File: SortMeApp.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

	FXMLLoader fxmlLoader = new FXMLLoader( SortMeApp.class.getResource("/sortme-fxml/SortMe.fxml") );
	Parent p = fxmlLoader.load();
	
	Scene scene = new Scene(p);
	scene.getStylesheets().add( "/sortme-css/sortme.css" );
	
	primaryStage.setScene( scene );
	primaryStage.setTitle( "SortMeApp" );
	primaryStage.setOnShown((evt)-> {
		SortMeController controller = (SortMeController)fxmlLoader.getController();
		controller.shuffle();
	});
	primaryStage.show();
}
 
Example 4
Source File: DebugDialog.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public DebugDialog()
{
	GuiAssertions.assertIsJavaFXThread();
	FXMLLoader loader = new FXMLLoader();
	loader.setResources(LanguageBundle.getBundle());
	loader.setLocation(getClass().getResource("DebugDialog.fxml"));
	primaryStage = new Stage();
	final Scene scene;
	try
	{
		scene = loader.load();
	} catch (IOException e)
	{
		Logging.errorPrint("failed to load debugdialog", e);
		return;
	}
	primaryStage.setScene(scene);
	DebugDialogController controller = loader.getController();
	primaryStage.setOnShown(e -> controller.initTimer());
}
 
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: SimpleWebServer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("Simple Web Server");
    BorderPane root = new BorderPane();
    TextArea area = new TextArea();
    root.setCenter(area);
    ToolBar bar = new ToolBar();
    Button openInBrowser = FXUIUtils.createButton("open-in-browser", "Open in External Browser", true);
    openInBrowser.setOnAction((event) -> {
        try {
            Desktop.getDesktop().browse(URI.create(webRoot));
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    Button changeRoot = FXUIUtils.createButton("fldr_closed", "Change Web Root", true);
    changeRoot.setOnAction((event) -> {
        DirectoryChooser chooser = new DirectoryChooser();
        File showDialog = chooser.showDialog(primaryStage);
        if (showDialog != null)
            server.setRoot(showDialog);
    });
    bar.getItems().add(openInBrowser);
    bar.getItems().add(changeRoot);
    root.setTop(bar);
    System.setOut(new PrintStream(new Console(area)));
    System.setErr(new PrintStream(new Console(area)));
    area.setEditable(false);
    primaryStage.setScene(new Scene(root));
    primaryStage.setOnShown((e) -> startServer(getParameters().getRaw()));
    primaryStage.show();
}
 
Example 7
Source File: ListSelectionUI.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
public MainPane(Stage stage)
{
    this.stage = stage;
    available = FXCollections.observableArrayList();
    selected  = FXCollections.observableArrayList();

    for (int i = 0; i < 50; i++)
        available.add("item " + i);

    stage.setOnShown(event -> Platform.runLater(this::showDialog));
}
 
Example 8
Source File: BackgroundApp.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

	FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/background-fxml/Background.fxml") );
	Parent p = fxmlLoader.load();
	
	BackgroundController c = fxmlLoader.getController();
	
	Scene scene = new Scene(p);
	
	primaryStage.setTitle( "BackgroundApp" );
	primaryStage.setScene( scene );
	primaryStage.setOnShown( (evt) -> c.startAmination() );
	primaryStage.show();
}
 
Example 9
Source File: ImprovedBackgroundApp.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

	FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/background-fxml/ImprovedBackground.fxml") );
	Parent p = fxmlLoader.load();
	
	ImprovedBackgroundController c = fxmlLoader.getController();
	
	Scene scene = new Scene(p);
	
	primaryStage.setTitle( "ImprovedBackgroundApp" );
	primaryStage.setScene( scene );
	primaryStage.setOnShown( (evt) -> c.startAmination() );
	primaryStage.show();
}
 
Example 10
Source File: TVTableApp.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

    FXMLLoader fxmlLoader = new FXMLLoader( TVTableApp.class.getResource("/tvtable-fxml/TVTable.fxml"));

    Parent p = fxmlLoader.load();

    TVTableController c = fxmlLoader.getController();

    Scene scene = new Scene(p, 1024, 768);
    scene.getStylesheets().add( "css/tvtable.css" );

    primaryStage.setScene( scene );
    primaryStage.setOnShown( (evt) -> c.load() );
    primaryStage.show();
}
 
Example 11
Source File: AccessControlMain.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) {

    try {

        FXMLLoader fxmlLoader = new FXMLLoader(AccessControlMain.class.getResource("/fxml/MainView.fxml"));

        Parent p = fxmlLoader.load();

        MainViewController mainView = fxmlLoader.getController();

        Scene scene = new Scene(p);

        primaryStage.setTitle("Access Control");
        primaryStage.setScene(scene);
        primaryStage.setOnShown( (evt) ->  mainView.init() );
        primaryStage.show();

    } catch(IOException exc) {
        log.error( "can't load /fxml/MainView.fxml", exc);
    }
}