本文整理匯總了Java中javafx.scene.control.Button.setOnKeyPressed方法的典型用法代碼示例。如果您正苦於以下問題:Java Button.setOnKeyPressed方法的具體用法?Java Button.setOnKeyPressed怎麽用?Java Button.setOnKeyPressed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.control.Button
的用法示例。
在下文中一共展示了Button.setOnKeyPressed方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createButton
import javafx.scene.control.Button; //導入方法依賴的package包/類
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;
}
示例2: buildButton
import javafx.scene.control.Button; //導入方法依賴的package包/類
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;
}
示例3: Mesazhi
import javafx.scene.control.Button; //導入方法依賴的package包/類
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();
}