Java Code Examples for javafx.scene.control.Alert#setHeaderText()

The following examples show how to use javafx.scene.control.Alert#setHeaderText() . 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 check out the related API usage on the sidebar.
Example 1
Source File: ScreensSwitcher.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
public boolean exitDialog(Stage stage) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.initOwner(stage);
alert.setTitle("Confirmation for Exit");//("Confirmation Dialog");
alert.setHeaderText("Leaving mars-sim ?");
//alert.initModality(Modality.APPLICATION_MODAL);
alert.setContentText("Note: Yes to exit mars-sim");
ButtonType buttonTypeYes = new ButtonType("Yes");
ButtonType buttonTypeNo = new ButtonType("No");
  	alert.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo);
  	Optional<ButtonType> result = alert.showAndWait();
  	if (result.get() == buttonTypeYes){
  		if (mainMenu.getMultiplayerMode() != null)
  			if (mainMenu.getMultiplayerMode().getChoiceDialog() != null)
  				mainMenu.getMultiplayerMode().getChoiceDialog().close();
  		alert.close();
	Platform.exit();
  		System.exit(0);
  		return true;
  	} else {
  		alert.close();
  	    return false;
  	}
 	}
 
Example 2
Source File: Archivo.java    From archivo with GNU General Public License v3.0 6 votes vote down vote up
private boolean confirmDelete(Recording recording, Tivo tivo) {
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle("Remove Recording Confirmation");
    alert.setHeaderText("Really remove this recording?");
    alert.setContentText(String.format("Are you sure you want to delete %s from %s?",
            recording.getFullTitle(), tivo.getName()));

    ButtonType deleteButtonType = new ButtonType("Delete", ButtonBar.ButtonData.NO);
    ButtonType keepButtonType = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);

    alert.getButtonTypes().setAll(deleteButtonType, keepButtonType);
    ((Button) alert.getDialogPane().lookupButton(deleteButtonType)).setDefaultButton(false);
    ((Button) alert.getDialogPane().lookupButton(keepButtonType)).setDefaultButton(true);

    Optional<ButtonType> result = alert.showAndWait();
    if (!result.isPresent()) {
        logger.error("No result from alert dialog");
        return false;
    } else {
        return (result.get() == deleteButtonType);
    }
}
 
Example 3
Source File: App.java    From xltsearch with Apache License 2.0 6 votes vote down vote up
@FXML
private void openFolder() {
    if (catalog.get().isIndexing()) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle("Confirmation");
        alert.setHeaderText("Indexing in progress");
        alert.setContentText("Opening a new folder will cancel indexing. Continue?");
        Optional<ButtonType> result = alert.showAndWait();
        // escape on cancel/close
        if (!result.isPresent() || result.get() != ButtonType.OK) {
            return;
        }
    }
    DirectoryChooser directoryChooser = new DirectoryChooser();
    File dir = directoryChooser.showDialog(stage);
    if (dir != null) {
        if (catalog.get() != null) {
            catalog.get().close();
        }
        catalog.set(new Catalog(dir));
    }  // do nothing on cancel
}
 
Example 4
Source File: ScenarioConfigEditorFX.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
public boolean confirmDeleteDialog(String header, String text) {
	Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);
	dialog.initOwner(stage);
	dialog.setHeaderText(header);
	dialog.setContentText(text);
	dialog.getDialogPane().setPrefSize(300, 180);
	// ButtonType buttonTypeYes = new ButtonType("Yes");
	// ButtonType buttonTypeNo = new ButtonType("No");
	// dialog.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo);
	dialog.getButtonTypes().clear();
	dialog.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO);
	// Deactivate Defaultbehavior for yes-Button:
	Button yesButton = (Button) dialog.getDialogPane().lookupButton(ButtonType.YES);
	yesButton.setDefaultButton(false);
	// Activate Defaultbehavior for no-Button:
	Button noButton = (Button) dialog.getDialogPane().lookupButton(ButtonType.NO);
	noButton.setDefaultButton(true);
	final Optional<ButtonType> result = dialog.showAndWait();
	// return result.get() == buttonTypeYes;
	return result.get() == ButtonType.YES;
}
 
Example 5
Source File: ServiceWindow.java    From ns-usbloader with GNU General Public License v3.0 6 votes vote down vote up
/** Real window creator */
private static void getNotification(String title, String body, Alert.AlertType type){
    Alert alertBox = new Alert(type);
    alertBox.setTitle(title);
    alertBox.setHeaderText(null);
    alertBox.setContentText(body);
    alertBox.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
    alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
    alertBox.setResizable(true);        // Java bug workaround for JDR11/OpenJFX. TODO: nothing. really.
    alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());

    Stage dialogStage = (Stage) alertBox.getDialogPane().getScene().getWindow();
    dialogStage.setAlwaysOnTop(true);
    dialogStage.getIcons().addAll(
            new Image("/res/warn_ico32x32.png"),
            new Image("/res/warn_ico48x48.png"),
            new Image("/res/warn_ico64x64.png"),
            new Image("/res/warn_ico128x128.png")
    );
    alertBox.show();
    dialogStage.toFront();
}
 
Example 6
Source File: FXMLTimingController.java    From pikatimer with GNU General Public License v3.0 6 votes vote down vote up
public void resetTimingLocations(ActionEvent fxevent){
    // prompt 
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle("Confirm Resetting all Timing Locations");
    alert.setHeaderText("This action cannot be undone.");
    alert.setContentText("This will reset the timing locations to default values.\nAll splits will be reassigned to one of the default locations.");
    //Label alertContent = new Label("This will reset the timing locations to default values.\nAll splits will be reassigned to one of the default locations.");
    //alertContent.setWrapText(true); 
    //alert.getDialogPane().setContent(alertContent);
    
    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
        timingDAO.createDefaultTimingLocations();
    } else {
        // ... user chose CANCEL or closed the dialog
    }
    
    timingLocAddButton.requestFocus();
    //timingLocAddButton.setDefaultButton(true);
}
 
Example 7
Source File: ShareFolderUILoader.java    From PeerWasp with MIT License 6 votes vote down vote up
private static void showError(final String message) {
	Runnable dialog = new Runnable() {
		@Override
		public void run() {
			Alert dlg = DialogUtils.createAlert(AlertType.ERROR);
			dlg.setTitle("Error Share Folder.");
			dlg.setHeaderText("Could not share folder.");
			dlg.setContentText(message);
			dlg.showAndWait();
		}
	};

	if (Platform.isFxApplicationThread()) {
		dialog.run();
	} else {
		Platform.runLater(dialog);
	}
}
 
Example 8
Source File: RecoverFileController.java    From PeerWasp with MIT License 6 votes vote down vote up
private void onFileRecoveryFailed(final String message) {
	Runnable failed = new Runnable() {
		@Override
		public void run() {
			setBusy(false);
			setStatus("");

			if(!versionSelector.isCancelled()) {
				// show error if user did not initiate cancel action
				Alert dlg = DialogUtils.createAlert(AlertType.ERROR);
				dlg.setTitle("File Recovery Failed");
				dlg.setHeaderText("File recovery did not succeed.");
				dlg.setContentText(message);
				dlg.showAndWait();
			}
			getStage().close();
		}
	};

	if (Platform.isFxApplicationThread()) {
		failed.run();
	} else {
		Platform.runLater(failed);
	}
}
 
Example 9
Source File: FXMLEventController.java    From pikatimer with GNU General Public License v3.0 6 votes vote down vote up
public void resetRaces(ActionEvent fxevent){
    // prompt 
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle("Confirm Resetting All Races");
    alert.setContentText("This action cannot be undone.");
    alert.setHeaderText("This will delete all configured races!");
    //Label alertContent = new Label("This will reset the timing locations to default values.\nAll splits will be reassigned to one of the default locations.");
    //alertContent.setWrapText(true); 
    //alert.getDialogPane().setContent(alertContent);
    
    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
        raceDAO.clearAll();
    } else {
        // ... user chose CANCEL or closed the dialog
    }
    
    raceAddButton.requestFocus();
    raceAddButton.setDefaultButton(true);
}
 
Example 10
Source File: AdminPanelController.java    From Online-Food-Ordering-System with MIT License 5 votes vote down vote up
public static void infoBox(String infoMessage, String headerText, String title){
    Alert alert = new Alert(Alert.AlertType.INFORMATION);
    alert.setContentText(infoMessage);
    alert.setTitle(title);
    alert.setHeaderText(headerText);
    alert.showAndWait();
}
 
Example 11
Source File: GUIController.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
public void showAboutInformationAlert() {
    Alert aboutInfo = new Alert(Alert.AlertType.INFORMATION);
    
    aboutInfo.setTitle("Sobre o Software");
    aboutInfo.setHeaderText("Sistema de Gerênciamento para Lojas de Informática.");
    aboutInfo.setContentText("Software desenvolvido como trabalho prático para a \ndiscíplina de Programação Desktop.\n");
    
    DialogPane diagPanel = aboutInfo.getDialogPane();
    diagPanel.getStylesheets().add(getClass().getResource("css/alert.css").toExternalForm());
    aboutInfo.showAndWait();
}
 
Example 12
Source File: ValidationController.java    From School-Management-System with Apache License 2.0 5 votes vote down vote up
public boolean validateNIC(TextField txt) {
    if (txt.getText().matches("^(\\d{9}|\\d{12})[VvXx]$")|| (txt.getText().isEmpty())) {

        return true;
    } else {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Student Registration");
        alert.setHeaderText(null);
        alert.setContentText("Invalid NIC Number..!");
        alert.showAndWait();

        return false;
    }
}
 
Example 13
Source File: DashboardController.java    From School-Management-System with Apache License 2.0 5 votes vote down vote up
@FXML
void btnLibraryMgmt(ActionEvent event) {
    Alert alert = new Alert(Alert.AlertType.INFORMATION);
    alert.setTitle("School Management System");
    alert.setHeaderText(null);
    alert.setContentText("Sorry..! This feature currently Unavailable for this Version.");
    alert.showAndWait();
}
 
Example 14
Source File: AlertMaker.java    From Library-Assistant with Apache License 2.0 5 votes vote down vote up
public static void showSimpleAlert(String title, String content) {
    Alert alert = new Alert(AlertType.INFORMATION);
    alert.setTitle(title);
    alert.setHeaderText(null);
    alert.setContentText(content);
    styleAlert(alert);
    alert.showAndWait();
}
 
Example 15
Source File: JFxBuilder.java    From Weather-Forecast with Apache License 2.0 5 votes vote down vote up
private void createAlertDialog(DialogObject dialog) {
    Alert alert = new Alert(dialog.getType());
    alert.setTitle(dialog.getTitle());
    alert.setHeaderText(dialog.getHeader());
    alert.setContentText(dialog.getContent());

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK) {
        System.exit(0);
    } else {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        dialog.getexception().printStackTrace(pw);
        String exceptionText = sw.toString();

        Label label = new Label("The exception stacktrace was:");

        TextArea textArea = new TextArea(exceptionText);
        textArea.setEditable(false);
        textArea.setWrapText(true);

        textArea.setMaxWidth(Double.MAX_VALUE);
        textArea.setMaxHeight(Double.MAX_VALUE);
        GridPane.setVgrow(textArea, Priority.ALWAYS);
        GridPane.setHgrow(textArea, Priority.ALWAYS);

        GridPane expContent = new GridPane();
        expContent.setMaxWidth(Double.MAX_VALUE);
        expContent.add(label, 0, 0);
        expContent.add(textArea, 0, 1);

        alert.getDialogPane().setExpandableContent(expContent);

        alert.showAndWait();
    }
}
 
Example 16
Source File: MultiplayerTray.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void createAlert(String text) {
   	//Stage stage = new Stage();
       stage.getIcons().add(new Image(this.getClass().getResource("/icons/lander_hab.svg").toString()));
       String header = null;
       //String text = null;
       header = "Multiplayer Host Server";
       //System.out.println("confirm dialog pop up.");
	Alert alert = new Alert(AlertType.CONFIRMATION);
	alert.initOwner(stage);
	alert.setTitle("Mars Simulation Project");
	alert.setHeaderText(header);
	alert.setContentText(text);
	alert.initModality(Modality.APPLICATION_MODAL);

	Optional<ButtonType> result = alert.showAndWait();
	if (result.get() == ButtonType.YES){
		if (multiplayerServer != null) {
        	// TODO: fix the loading problem for server mode
        	multiplayerServer.setServerStopped(true);
        }
		notificationTimer.cancel();
		Platform.exit();
		tray.remove(trayIcon);
	    System.exit(0);
	}
	//else {
	//}
}
 
Example 17
Source File: DialogMediator.java    From metastone with GNU General Public License v2.0 5 votes vote down vote up
private void displayErrorMessage(String header, String message) {
	Alert alert = new Alert(AlertType.ERROR);
	alert.setTitle("Error");
	alert.setHeaderText(header);
	alert.setContentText(message);
	alert.showAndWait();
}
 
Example 18
Source File: EchoClientControllerWS.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@FXML
public void disconnect() {
	
	if( !connected.get() ) {
		if( logger.isWarnEnabled() ) {
			logger.warn("client not connected; skipping disconnect");
		}
		return;
	}
	
	if( logger.isDebugEnabled() ) {
		logger.debug("[DISCONNECT]");
	}
	
	Task<Void> task = new Task<Void>() {

		@Override
		protected Void call() throws Exception {
			
			updateMessage("Disconnecting");
			updateProgress(0.1d, 1.0d);
			
			channel.close().sync();					

			updateMessage("Closing group");
			updateProgress(0.5d, 1.0d);
			group.shutdownGracefully().sync();

			return null;
		}

		@Override
		protected void succeeded() {
			
			connected.set(false);
		}

		@Override
		protected void failed() {
			
			connected.set(false);

			Throwable t = getException();
			logger.error( "client disconnect error", t );
			Alert alert = new Alert(AlertType.ERROR);
			alert.setTitle("Client");
			alert.setHeaderText( t.getClass().getName() );
			alert.setContentText( t.getMessage() );
			alert.showAndWait();

		}
		
	};
	
	hboxStatus.visibleProperty().bind( task.runningProperty() );
	lblStatus.textProperty().bind( task.messageProperty() );
	piStatus.progressProperty().bind(task.progressProperty());

	new Thread(task).start();
}
 
Example 19
Source File: FXMLEventController.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
public void removeRace(ActionEvent fxevent){
    
    final Race r = raceTableView.getSelectionModel().getSelectedItem();
    
    if (r == null) return;
    
    // Do we have any runner's assigned?
    BooleanProperty assignedRunners = new SimpleBooleanProperty(false);
    BooleanProperty assignedTimingLoc= new SimpleBooleanProperty(false);
    StringProperty assignedTimingLocations = new SimpleStringProperty();

    ParticipantDAO.getInstance().listParticipants().forEach(x ->{
        x.getWaveIDs().forEach(w -> {
            if (RaceDAO.getInstance().getWaveByID(w).getRace().equals(r)) {
                assignedRunners.setValue(Boolean.TRUE);
                //System.out.println("Race " + RaceDAO.getInstance().getWaveByID(w).getRace().getRaceName() + " is in use by " + x.fullNameProperty().getValueSafe());
            }
        });
    });
    
    TimingDAO.getInstance().listTimingLocations().forEach(x -> {
        if (x.getAutoAssignRaceID() >= 0 ) {
            assignedTimingLoc.setValue(Boolean.TRUE);
            if (assignedTimingLocations.isEmpty().get()) assignedTimingLocations.setValue(x.getLocationName());
            else assignedTimingLocations.setValue(assignedTimingLocations.getValue() + "\n" + x.getLocationName());
        }
    });
    
    if (assignedRunners.get() || assignedTimingLoc.get()) {
        Alert alert = new Alert(AlertType.INFORMATION);
        alert.setTitle("Unable to Remove Race");
        alert.setHeaderText("Unable to remove the selected race.");
        if (assignedRunners.get()) alert.setContentText("This race currently has assigned runners.\nPlease assign them to a different race before removing.");
        if (assignedTimingLoc.get()) alert.setContentText("The following timing locations are set to\nauto-assign runners to this race:\n\n"+assignedTimingLocations.getValueSafe());

        alert.showAndWait();
    } else {
        raceDAO.removeRace(raceTableView.getSelectionModel().getSelectedItem());
        raceTableView.getSelectionModel().select(raceList.indexOf(0));
        raceAddButton.requestFocus();
        raceAddButton.setDefaultButton(false);

        if (raceList.size() > 1) { 
            multipleRacesCheckBox.setDisable(true);
            raceRemoveButton.setDisable(false); 
        } else {
            multipleRacesCheckBox.setDisable(false);
            raceRemoveButton.setDisable(true);
        }
    }
   
}
 
Example 20
Source File: TemplateListDialog.java    From constellation with Apache License 2.0 4 votes vote down vote up
String getName(final Object owner, final File delimIoDir) {
    final String[] templateLabels = getFileLabels(delimIoDir);

    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);

    final TextField label = new TextField();
    label.setPromptText("Template label");

    final ObservableList<String> q = FXCollections.observableArrayList(templateLabels);
    final ListView<String> nameList = new ListView<>(q);
    nameList.setEditable(false);
    nameList.setOnMouseClicked(event -> {
        label.setText(nameList.getSelectionModel().getSelectedItem());
        if (event.getClickCount() > 1) {
            dialog.setResult(ButtonType.OK);
        }
    });

    final HBox prompt = new HBox(new Label("Name: "), label);
    prompt.setPadding(new Insets(10, 0, 0, 0));

    final VBox vbox = new VBox(nameList, prompt);

    dialog.setResizable(false);
    dialog.setTitle("Import template names");
    dialog.setHeaderText(String.format("Select an import template to %s.", isLoading ? "load" : "save"));
    dialog.getDialogPane().setContent(vbox);
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        final String name = label.getText();
        final File f = new File(delimIoDir, FilenameEncoder.encode(name + ".json"));
        boolean go = true;
        if (!isLoading && f.exists()) {
            final String msg = String.format("'%s' already exists. Do you want to overwrite it?", name);
            final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setHeaderText("Import template exists");
            alert.setContentText(msg);
            final Optional<ButtonType> confirm = alert.showAndWait();
            go = confirm.isPresent() && confirm.get() == ButtonType.OK;
        }

        if (go) {
            return name;
        }
    }

    return null;
}