本文整理汇总了Java中javafx.stage.Window.setOnCloseRequest方法的典型用法代码示例。如果您正苦于以下问题:Java Window.setOnCloseRequest方法的具体用法?Java Window.setOnCloseRequest怎么用?Java Window.setOnCloseRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.stage.Window
的用法示例。
在下文中一共展示了Window.setOnCloseRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showDialog
import javafx.stage.Window; //导入方法依赖的package包/类
public void showDialog() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gui/diff/diff-view.fxml"));
try {
loader.setController(diffController);
DialogPane root = loader.load();
root.getStylesheets().add(getClass().getResource("/gui/diff/diff-view.css").toExternalForm());
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Diff Viewer");
alert.setResizable(true);
alert.setDialogPane(root);
alert.initModality(Modality.WINDOW_MODAL);
Window window = alert.getDialogPane().getScene().getWindow();
window.setOnCloseRequest(event -> window.hide());
alert.showAndWait();
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: showDialog
import javafx.stage.Window; //导入方法依赖的package包/类
public boolean showDialog() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gui/conflict/resolve-conflicts-view.fxml"));
try {
loader.setController(conflictManagerController);
DialogPane root = loader.load();
root.getStylesheets().add(getClass().getResource("/gui/conflict/resolve-conflicts-view.css").toExternalForm());
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Resolve conflicts");
alert.setResizable(true);
alert.setDialogPane(root);
alert.initModality(Modality.WINDOW_MODAL);
Window window = alert.getDialogPane().getScene().getWindow();
window.setOnCloseRequest(event -> window.hide());
alert.showAndWait();
} catch (IOException e) {
e.printStackTrace();
}
return conflictManagerController.isFinishedSuccessfully();
}
示例3: SellProductDialog
import javafx.stage.Window; //导入方法依赖的package包/类
/**
* @param choices
* @param product
* @param controller
* return a dialog that permittes to choose the supplier to restock
*/
public SellProductDialog(ObservableList<Client> choices, Product product, ProductController controller) {
setTitle("Vente d'un produit");
dialogPane = getDialogPane();
dialogPane.setPrefSize(SELL_PRODUCT_WIDTH, SELL_PRODUCT_HEIGHT);
header.setMinWidth(SELL_PRODUCT_WIDTH);
ComboBox<Client> clients = new ComboBox<>();
clients.setItems(choices);
clients.setMinSize(SELL_PRODUCT_WIDTH * 0.8, SELL_PRODUCT_HEIGHT * 0.1);
clients.getSelectionModel().selectFirst();
VBox.setMargin(clients, new Insets(0, 0, 0, SELL_PRODUCT_WIDTH * 0.1));
Spinner<Integer> qttField = new Spinner<>(1, product.getStock(), 1);
qttField.setMinWidth(SELL_PRODUCT_WIDTH * 0.3);
qttField.setStyle("-fx-font-size: 18px");
VBox.setMargin(qttField, new Insets(0, 0, 0, SELL_PRODUCT_WIDTH * 0.1));
HBox buttons = new HBox();
Button cancel = new Button("Annuler");
cancel.setMinWidth(SELL_PRODUCT_WIDTH * 0.3);
Button validate = new Button("Confimer");
validate.setMinWidth(SELL_PRODUCT_WIDTH * 0.3);
buttons.setSpacing(SELL_PRODUCT_WIDTH * 0.2);
buttons.getChildren().addAll(cancel, validate);
VBox.setMargin(buttons, new Insets(SELL_PRODUCT_HEIGHT * 0.2, 0, 0, SELL_PRODUCT_WIDTH * 0.1));
wrapper.setPrefSize(SELL_PRODUCT_WIDTH , SELL_PRODUCT_HEIGHT * 0.9);
wrapper.setSpacing(SELL_PRODUCT_WIDTH * 0.05);
wrapper.getChildren().addAll(header, clients, qttField, buttons);
dialogPane.getChildren().add(wrapper);
Window window = getDialogPane().getScene().getWindow();
window.setOnCloseRequest(event -> window.hide());
cancel.setOnMouseClicked(event -> window.hide());
validate.setOnMouseClicked(event -> {
GenericDAO<Purchase, Integer> dao = new GenericDAO<>(Purchase.class);
Purchase purchase = new Purchase();
purchase.setDatetime(new Timestamp(System.currentTimeMillis()));
purchase.setQuantity(qttField.getValue());
purchase.setProduct(product);
purchase.setClient(clients.getSelectionModel().getSelectedItem());
dao.save(purchase);
product.setStock(product.getStock() - purchase.getQuantity());
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Succés");
alert.setHeaderText("La vente a été enregistrée.");
alert.showAndWait();
window.hide();
});
}