本文整理匯總了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();
});
}