8
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Stuff");
alert.setContentText(messageIWannaCopy());
conf.show();

I'm creating an alert in JavaFX. But I'd like the user to be able to copy the message to the clipboard. How can I do that? By default it looks like a standard label, which doesn't allow that.

1 Answer 1

8

this might what you need

TextArea textArea = new TextArea("YOUR_MESSAGE_HERE");
textArea.setEditable(false);
textArea.setWrapText(true);
GridPane gridPane = new GridPane();
gridPane.setMaxWidth(Double.MAX_VALUE);
gridPane.add(textArea, 0, 0);

Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Stuff");
alert.getDialogPane().setContent(gridPane);
alert.showAndWait();
1
  • Nailed it! Thank you!
    – Steve
    Commented Aug 10, 2017 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.