javafx.scene.control.Alert.getButtonTypes()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中javafx.scene.control.Alert.getButtonTypes()方法的一些代码示例,展示了Alert.getButtonTypes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Alert.getButtonTypes()方法的具体详情如下:
包路径:javafx.scene.control.Alert
类名称:Alert
方法名:getButtonTypes

Alert.getButtonTypes介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public boolean showConfirmDialog(String title, String header, String content, AlertType alertType) {
  final Alert alert = new Alert(alertType);
  alert.setTitle(title);
  alert.setHeaderText(header);
  alert.setContentText(content);

  alert.getButtonTypes().clear();
  alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO);

  //Deactivate Defaultbehavior for yes-Button:
  Button yesButton = (Button) alert.getDialogPane().lookupButton( ButtonType.YES );
  yesButton.setDefaultButton( false );

  //Activate Defaultbehavior for no-Button:
  Button noButton = (Button) alert.getDialogPane().lookupButton( ButtonType.NO );
  noButton.setDefaultButton( true );

  final Optional<ButtonType> result = alert.showAndWait();
  return result.get() == ButtonType.YES;
}

代码示例来源:origin: com.powsybl/powsybl-gse-util

public static Optional<ButtonType> showSaveAndQuitDialog(String documentName) {
  Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
  alert.setHeaderText(MessageFormat.format(RESOURCE_BUNDLE.getString("SaveBeforeClosing"), documentName));
  alert.setContentText(RESOURCE_BUNDLE.getString("WarnSaveBeforeClosing"));
  ButtonType save = new ButtonType(RESOURCE_BUNDLE.getString("Save"), ButtonBar.ButtonData.YES);
  ButtonType dontSave = new ButtonType(RESOURCE_BUNDLE.getString("DontSave"), ButtonBar.ButtonData.NO);
  alert.getButtonTypes().setAll(save, dontSave, ButtonType.CANCEL);
  return alert.showAndWait();
}

代码示例来源:origin: stackoverflow.com

ButtonType buttonTypeOne = new ButtonType("Yes");
ButtonType buttonTypeCancel = new ButtonType("No", ButtonBar.ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);

代码示例来源:origin: org.tentackle/tentackle-fx

/**
 * Shows a question dialog.
 *
 * @param message the message
 * @param defaultYes true if yes is the default button
 * @return true if yes, false if no
 */
public boolean showQuestionDialog(String message, boolean defaultYes) {
 Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
 alert.setTitle(FxFxBundle.getString("QUESTION"));
 setAlertMessage(alert, message);
 alert.getButtonTypes().clear();
 alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO);
 Button noButton = (Button) alert.getDialogPane().lookupButton(ButtonType.NO);
 Button yesButton = (Button) alert.getDialogPane().lookupButton(ButtonType.YES);
 noButton.setDefaultButton(!defaultYes);
 yesButton.setDefaultButton(defaultYes);
 Optional<ButtonType> result = alert.showAndWait();
 return result.isPresent() && result.get() == ButtonType.YES;
}

代码示例来源:origin: stackoverflow.com

alert.initModality( Modality.NONE );
ButtonType buttonTypeCancel = new ButtonType( "No", ButtonBar.ButtonData.CANCEL_CLOSE );
alert.getButtonTypes().setAll( buttonTypeOne, buttonTypeCancel );

代码示例来源:origin: com.nexitia.emaginplatform/emagin-jfxcore-engine

public static String showConfirm(String title, String message, String... options) {
 final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
 alert.initStyle(StageStyle.UTILITY);
 alert.setTitle("Choose an option");
 alert.setHeaderText(title);
 alert.setContentText(message);
 // To make enter key press the actual focused button, not the first one.
 // Just like pressing
 // "space".
 alert.getDialogPane().addEventFilter(KeyEvent.KEY_PRESSED, event -> {
  if (event.getCode().equals(KeyCode.ENTER)) {
   event.consume();
  }
 });
 if (options == null || options.length == 0) {
  options = new String[] {OK, CANCEL};
 }
 final List<ButtonType> buttons = new ArrayList<>();
 for (final String option : options) {
  buttons.add(new ButtonType(option));
 }
 alert.getButtonTypes().setAll(buttons);
 final Optional<ButtonType> result = alert.showAndWait();
 if (!result.isPresent()) {
  return CANCEL;
 } else {
  return result.get().getText();
 }
}

代码示例来源:origin: ssaring/sportstracker

@Override
public Optional<ButtonType> showConfirmationDialog(final Window parent, final String titleKey,
    final String messageKey, final ButtonType... buttonTypes) {
  final Alert alert = new Alert(Alert.AlertType.CONFIRMATION, fxResources.getString(messageKey));
  alert.initOwner(parent);
  alert.setTitle(fxResources.getString(titleKey));
  alert.setHeaderText(null);
  // add custom button types if specified
  if (buttonTypes.length > 0) {
    alert.getButtonTypes().setAll(buttonTypes);
  }
  return alert.showAndWait();
}

代码示例来源:origin: com.canoo.dolphin-platform/dolphin-platform-client-javafx

alert.getButtonTypes().addAll(reconnect);

相关文章