本文整理汇总了Java中javafx.stage.Stage.setOnShown方法的典型用法代码示例。如果您正苦于以下问题:Java Stage.setOnShown方法的具体用法?Java Stage.setOnShown怎么用?Java Stage.setOnShown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.stage.Stage
的用法示例。
在下文中一共展示了Stage.setOnShown方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProgressBarView
import javafx.stage.Stage; //导入方法依赖的package包/类
/**
* Create instance of {@link ProgressBarView}.
*/
public ProgressBarView() {
try {
final Stage newStage = new Stage();
newStage.setResizable(false);
final URL resource = getClass().getResource(PROGRESS_BAR_VIEW);
fxmlLoader = new FXMLLoader(resource);
final Stage primaryStage = Hygene.getInstance().getPrimaryStage();
newStage.initOwner(primaryStage);
newStage.initStyle(StageStyle.UTILITY);
newStage.initModality(Modality.APPLICATION_MODAL);
final double centerXPosition = primaryStage.getX() + primaryStage.getWidth() / 2;
final double centerYPosition = primaryStage.getY() + primaryStage.getHeight() / 2;
newStage.setOnShowing(event -> newStage.hide());
newStage.setOnShown(event -> {
newStage.setX(centerXPosition - newStage.getWidth() / 2);
newStage.setY(centerYPosition - newStage.getHeight() / 2);
newStage.show();
});
setStage(newStage);
} catch (final UIInitialisationException e) {
LOGGER.error("Progress bar view could not be loaded.", e);
}
}
示例2: start
import javafx.stage.Stage; //导入方法依赖的package包/类
@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();
}