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

The following are Jave code examples for showing how to use setOnKeyPressed() of the javafx.scene.control.Button class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: NoMoreOversleeps   File: JavaFxHelper.java   Source Code and License Vote up 5 votes
public static Button createButton()
{
	final Button button = new Button();
	button.setOnKeyPressed(new EventHandler<KeyEvent>()
	{
		@Override
		public void handle(KeyEvent evt)
		{
			if (evt.getCode() == KeyCode.ENTER)
				button.fire();
		}
	});
	return button;
}
 
Example 2
Project: cassandra-client   File: NewConnectionBox.java   Source Code and License Vote up 5 votes
private Button buildButton() {
    Button submit = new Button(localeService.getMessage("ui.menu.file.connect.submit.text"));
    submit.setAlignment(Pos.CENTER);
    submit.setOnAction(this::handleClick);
    submit.setOnKeyPressed(event -> {
        if (event.getCode() == KeyCode.ENTER) {
            handleClick(event);
        }
    });
    return submit;
}
 
Example 3
Project: Automekanik   File: Mesazhi.java   Source Code and License Vote up 5 votes
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 4
Project: Automekanik   File: Mesazhi.java   Source Code and License Vote up 4 votes
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 5
Project: Automekanik   File: Mesazhi.java   Source Code and License Vote up 4 votes
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 6
Project: Automekanik   File: Mesazhi.java   Source Code and License Vote up 4 votes
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();
}