Java Code Examples for javafx.scene.control.Button#setOnKeyPressed()

The following examples show how to use javafx.scene.control.Button#setOnKeyPressed() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: ARMStrong   File: Gui.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * display a warning popup
 * @param message the message to display
 * @param okEvent an event fired when the user presses the ok button
 */
public static void warningPopup(String message, EventHandler<ActionEvent> okEvent) {
	final Stage warningStage = new Stage();
	warningStage.setTitle("Warning");

	warningStage.initModality(Modality.APPLICATION_MODAL);
	warningStage.setResizable(false);

	try {
		Pane main = FXMLLoader.load(Gui.class.getResource("/resources/warning.fxml"));
		warningStage.setScene(new Scene(main, 500, 280));

		Text messageText = (Text) main.lookup("#message");
		messageText.setText(message);

		ImageView image = (ImageView) main.lookup("#image");
		image.setImage(new Image(Gui.class.getResource("/resources/warning.png").toExternalForm()));

		Button okButton = (Button) main.lookup("#ok");
		Button cancelButton = (Button) main.lookup("#cancel");
		okButton.setOnAction(okEvent);
		okButton.setOnMouseReleased(mouseEvent -> warningStage.close());
		okButton.setOnKeyPressed(keyEvent -> warningStage.close());

		cancelButton.setOnAction(actionEvent1 -> warningStage.close());

	} catch (IOException e) {
		e.printStackTrace();
	}
	warningStage.show();
}
 
Example 2
public Mesazhi(String titulli, String titulli_msg, String mesazhi){
    stage.setTitle(titulli);
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setResizable(false);
    HBox root = new HBox(15);
    VBox sub_root = new VBox(10);
    HBox btn = new HBox();
    Text ttl = new Text(titulli_msg);
    ttl.setFont(Font.font(16));
    Button btnOk = new Button("Ne rregull");
    btn.getChildren().add(btnOk);
    btn.setAlignment(Pos.CENTER_RIGHT);

    btnOk.setOnAction(e -> stage.close());
    btnOk.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER)) stage.close();
        else if (e.getCode().equals(KeyCode.ESCAPE)) stage.close();
    });

    root.setPadding(new Insets(20));
    sub_root.getChildren().addAll(ttl, new Label(mesazhi), btn);
    if (titulli == "Gabim")
        root.getChildren().add(new ImageView(new Image("/sample/foto/error.png")));
    else if (titulli == "Sukses")
        root.getChildren().add(new ImageView(new Image("/sample/foto/success.png")));
    else if (titulli == "Informacion")
        root.getChildren().add(new ImageView(new Image("/sample/foto/question.png")));
    else if (titulli == "Info")
        root.getChildren().add(new ImageView(new Image("/sample/foto/info.png")));
    root.getChildren().add(sub_root);
    root.setAlignment(Pos.TOP_CENTER);
    Scene scene = new Scene(root, 450, 150);
    scene.getStylesheets().add(getClass().getResource("/sample/style.css").toExternalForm());
    stage.setScene(scene);
    stage.show();
}
 
Example 3
public Mesazhi(String titulli, String titulli_msg, String mesazhi, ShikoPunetoret sp, DritarjaKryesore dk){
    stage.setTitle(titulli);
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setResizable(false);
    Button btnAnulo = new Button("Anulo");
    HBox root = new HBox(15);
    VBox sub_root = new VBox(10);
    HBox btn = new HBox(5);
    Text ttl = new Text(titulli_msg);
    ttl.setFont(Font.font(16));
    Button btnOk = new Button("Ne rregull");
    btn.getChildren().addAll(btnAnulo, btnOk);
    btn.setAlignment(Pos.CENTER_RIGHT);

    btnOk.setOnAction(e -> {
        sp.fshi(sp.strEmri.toLowerCase() + sp.strMbiemri.toLowerCase());
        stage.close();
    });
    btnOk.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER)) stage.close();
        else if (e.getCode().equals(KeyCode.ESCAPE)) stage.close();
    });

    btnAnulo.setOnAction(e -> stage.close());

    root.setPadding(new Insets(20));
    sub_root.getChildren().addAll(ttl, new Label(mesazhi), btn);
    if (titulli == "Gabim")
        root.getChildren().add(new ImageView(new Image("/sample/foto/error.png")));
    else if (titulli == "Sukses")
        root.getChildren().add(new ImageView(new Image("/sample/foto/success.png")));
    else if (titulli == "Informacion")
        root.getChildren().add(new ImageView(new Image("/sample/foto/question.png")));
    else if (titulli == "Info")
        root.getChildren().add(new ImageView(new Image("/sample/foto/info.png")));
    root.getChildren().add(sub_root);
    root.setAlignment(Pos.TOP_CENTER);
    Scene scene = new Scene(root, 450, 150);
    scene.getStylesheets().add(getClass().getResource("/sample/style.css").toExternalForm());
    btnOk.isFocused();
    stage.setScene(scene);
    stage.show();
}
 
Example 4
public Mesazhi(String titulli, String titulli_msg, String mesazhi, ShikoKonsumatoret sk, int skId){
    stage.setTitle(titulli);
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setResizable(false);
    Button btnAnulo = new Button("Anulo");
    HBox root = new HBox(15);
    VBox sub_root = new VBox(10);
    HBox btn = new HBox(5);
    Text ttl = new Text(titulli_msg);
    ttl.setFont(Font.font(16));
    Button btnOk = new Button("Ne rregull");
    btn.getChildren().addAll(btnAnulo, btnOk);
    btn.setAlignment(Pos.CENTER_RIGHT);

    btnOk.setOnAction(e -> {
        sk.fshi(skId);
        stage.close();
    });
    btnOk.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER)) stage.close();
        else if (e.getCode().equals(KeyCode.ESCAPE)) stage.close();
    });

    btnAnulo.setOnAction(e -> stage.close());

    root.setPadding(new Insets(20));
    sub_root.getChildren().addAll(ttl, new Label(mesazhi), btn);
    if (titulli == "Gabim")
        root.getChildren().add(new ImageView(new Image("/sample/foto/error.png")));
    else if (titulli == "Sukses")
        root.getChildren().add(new ImageView(new Image("/sample/foto/success.png")));
    else if (titulli == "Informacion")
        root.getChildren().add(new ImageView(new Image("/sample/foto/question.png")));
    else if (titulli == "Info")
        root.getChildren().add(new ImageView(new Image("/sample/foto/info.png")));
    root.getChildren().add(sub_root);
    root.setAlignment(Pos.TOP_CENTER);
    Scene scene = new Scene(root, 450, 150);
    scene.getStylesheets().add(getClass().getResource("/sample/style.css").toExternalForm());
    btnOk.isFocused();
    stage.setScene(scene);
    stage.show();
}
 
Example 5
public Mesazhi(String titulli, String titulli_msg, String mesazhi, DritarjaKryesore sp){
    stage.setTitle(titulli);
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setResizable(false);
    Button btnAnulo = new Button("Anulo");
    HBox root = new HBox(15);
    VBox sub_root = new VBox(10);
    HBox btn = new HBox(5);
    Text ttl = new Text(titulli_msg);
    ttl.setFont(Font.font(16));
    Button btnOk = new Button("Ne rregull");
    btn.getChildren().addAll(btnAnulo, btnOk);
    btn.setAlignment(Pos.CENTER_RIGHT);

    btnOk.setOnAction(e -> {
        sp.fshi();
        stage.close();
    });
    btnOk.setOnKeyPressed(e -> {
        if (e.getCode().equals(KeyCode.ENTER)) stage.close();
        else if (e.getCode().equals(KeyCode.ESCAPE)) stage.close();
    });

    btnAnulo.setOnAction(e -> stage.close());

    root.setPadding(new Insets(20));
    sub_root.getChildren().addAll(ttl, new Label(mesazhi), btn);
    if (titulli == "Gabim")
        root.getChildren().add(new ImageView(new Image("/sample/foto/error.png")));
    else if (titulli == "Sukses")
        root.getChildren().add(new ImageView(new Image("/sample/foto/success.png")));
    else if (titulli == "Informacion")
        root.getChildren().add(new ImageView(new Image("/sample/foto/question.png")));
    else if (titulli == "Info")
        root.getChildren().add(new ImageView(new Image("/sample/foto/info.png")));
    root.getChildren().add(sub_root);
    root.setAlignment(Pos.TOP_CENTER);
    Scene scene = new Scene(root, 450, 150);
    scene.getStylesheets().add(getClass().getResource("/sample/style.css").toExternalForm());
    btnOk.isFocused();
    stage.setScene(scene);
    stage.show();
}