下面列出了javafx.scene.control.TextArea#setMaxHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void show()
{
final Hyperlink hyperlink = new Hyperlink("Google Cloud SDK");
hyperlink.setOnAction(e -> Paintera.getApplication().getHostServices().showDocument(googleCloudSdkLink));
final TextArea area = new TextArea(googleCloudAuthCmd);
area.setFont(Font.font("monospace"));
area.setEditable(false);
area.setMaxHeight(24);
final TextFlow textFlow = new TextFlow(
new Text("Please install "),
hyperlink,
new Text(" and then run this command to initialize the credentials:"),
new Text(System.lineSeparator() + System.lineSeparator()),
area);
final Alert alert = PainteraAlerts.alert(Alert.AlertType.INFORMATION);
alert.setHeaderText("Could not find Google Cloud credentials.");
alert.getDialogPane().contentProperty().set(textFlow);
alert.show();
}
public static Optional<ButtonType> showException(String header, Exception e) {
// 获取一个警告对象
Alert alert = getAlert(header, "错误信息追踪:", AlertType.ERROR);
// 打印异常信息
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
String exception = stringWriter.toString();
// 显示异常信息
TextArea textArea = new TextArea(exception);
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 gridPane = new GridPane();
gridPane.setMaxWidth(Double.MAX_VALUE);
gridPane.add(textArea, 0, 0);
alert.getDialogPane().setExpandableContent(gridPane);
return alert.showAndWait();
}
void setDetailsText(String details) {
GridPane content = new GridPane();
content.setMaxHeight(Double.MAX_VALUE);
Label label = new Label("Details:");
TextArea textArea = new TextArea(details);
textArea.setEditable(false);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
content.add(label, 0, 0);
content.add(textArea, 0, 1);
this.getDialogPane().setExpandableContent(content);
// work around DialogPane expandable content resize bug
this.getDialogPane().expandedProperty().addListener((ov, oldValue, newValue) -> {
Platform.runLater(() -> {
this.getDialogPane().requestLayout();
this.getDialogPane().getScene().getWindow().sizeToScene();
});
});
}
public static void showErrorMessage(Exception ex, String title, String content) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error occured");
alert.setHeaderText(title);
alert.setContentText(content);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.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();
}
@Override
protected void drawStepContent() {
super.drawStepContent();
TextArea licenceWidget = new TextArea(licenceText);
licenceWidget.setLayoutX(10);
licenceWidget.setLayoutY(100);
licenceWidget.setMinWidth(700);
licenceWidget.setMaxWidth(700);
licenceWidget.setMinHeight(308);
licenceWidget.setMaxHeight(308);
licenceWidget.setEditable(false);
CheckBox confirmWidget = new CheckBox(tr("I agree"));
confirmWidget.setOnAction(event -> {
isAgree = !isAgree;
confirmWidget.setSelected(isAgree);
setNextButtonEnabled(isAgree);
});
confirmWidget.setLayoutX(10);
confirmWidget.setLayoutY(418);
setNextButtonEnabled(false);
this.addToContentPane(licenceWidget);
this.addToContentPane(confirmWidget);
}
public ExceptionDialog(Throwable ex) {
super(AlertType.ERROR);
setTitle("Exception");
setHeaderText("Exception during startup of application");
setContentText(ex.getClass().getName() + ": " + ex.getMessage());
// Create expandable Exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.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);
// Set expandable Exception into the dialog pane.
getDialogPane().setExpandableContent(expContent);
}
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();
}
}
public static Alert createExceptionAlert( Exception e, String msg )
{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Exception Dialog");
alert.setHeaderText("Whoops!");
alert.setContentText(msg);
// Create expandable Exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.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);
// Set expandable Exception into the dialog pane.
alert.getDialogPane().setExpandableContent(expContent);
return alert;
}
static void showThrowable(String sender, String className, String message, List<StackTraceElement> stacktrace) {
if (!Main.getProperties().getBoolean("error-alerting", true)) return;
Alert alert = new Alert(Alert.AlertType.ERROR);
((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(new Image(App.ICON_URL.toString()));
alert.setTitle(Main.getString("error"));
alert.initModality(Modality.WINDOW_MODAL);
alert.setHeaderText(className + " " + Main.getString("caused-by") + " " + sender);
alert.setContentText(message);
StringBuilder exceptionText = new StringBuilder ();
for (Object item : stacktrace)
exceptionText.append((item != null ? item.toString() : "null") + "\n");
TextArea textArea = new TextArea(exceptionText.toString());
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
CheckBox checkBox = new CheckBox(Main.getString("enable-error-alert"));
checkBox.setSelected(Main.getProperties().getBoolean("error-alerting", true));
checkBox.selectedProperty().addListener((obs, oldValue, newValue) -> {
Main.getProperties().put("error-alerting", newValue);
});
BorderPane pane = new BorderPane();
pane.setTop(checkBox);
pane.setCenter(textArea);
alert.getDialogPane().setExpandableContent(pane);
alert.show();
}
/**
* 显示Exception的Dialog
*
* @param ex 异常
*/
public static void exception(Exception ex){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Exception Dialog");
alert.setHeaderText("Look, an Exception Dialog");
alert.setContentText("Could not find file blabla.txt!");
//Exception ex = new FileNotFoundException("Could not find file blabla.txt");
// Create expandable Exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.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);
// Set expandable Exception into the dialog pane.
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
public static void showException(Exception e) {
if (e != null) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Exception Alert!");
alert.setHeaderText("An Exception was thrown.");
alert.setContentText(e.getMessage());
// Create expandable Exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String exceptionText = sw.toString();
Label stackTraceHeaderLabel = new Label("The exception stacktrace was:");
TextArea stackTraceTextArea = new TextArea(exceptionText);
stackTraceTextArea.setEditable(false);
stackTraceTextArea.setWrapText(true);
stackTraceTextArea.setMaxWidth(Double.MAX_VALUE);
stackTraceTextArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(stackTraceTextArea, Priority.ALWAYS);
GridPane.setHgrow(stackTraceTextArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(stackTraceHeaderLabel, 0, 0);
expContent.add(stackTraceTextArea, 0, 1);
// Set expandable Exception into the dialog pane.
alert.getDialogPane().setExpandableContent(expContent);
alert.getDialogPane().setExpanded(true);
alert.showAndWait();
}
}
public static void showErrorMessage(Exception ex) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error occured");
alert.setHeaderText("Error Occured");
alert.setContentText(ex.getLocalizedMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.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);
styleAlert(alert);
alert.showAndWait();
}
@Override
public void gitExceptionDialog(String title, String header, String content, Exception e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(content);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("Exception stack trace:");
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();
}
public static void showDialog(final LockFile.UnableToCreateLock exception)
{
final Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Paintera");
alert.setHeaderText("Unable to create lock file.");
final Label instructions = new Label(
"If no other Paintera instance is accessing the same project please delete lock file and try to " +
"restart Paintera.");
instructions.setWrapText(true);
final GridPane content = new GridPane();
final Label fileLabel = new Label("Lock File");
final Label messageLabel = new Label("Message");
final TextField fileField = new TextField(exception.getLockFile().getAbsolutePath());
final TextField messageField = new TextField(exception.getMessage());
fileField.setTooltip(new Tooltip(fileField.getText()));
messageField.setTooltip(new Tooltip(messageField.getText()));
fileField.setEditable(false);
messageField.setEditable(false);
GridPane.setHgrow(fileField, Priority.ALWAYS);
GridPane.setHgrow(messageField, Priority.ALWAYS);
content.add(fileLabel, 0, 0);
content.add(messageLabel, 0, 1);
content.add(fileField, 1, 0);
content.add(messageField, 1, 1);
final VBox contentBox = new VBox(instructions, content);
alert.getDialogPane().setContent(contentBox);
final StringWriter stringWriter = new StringWriter();
exception.printStackTrace(new PrintWriter(stringWriter));
final String exceptionText = stringWriter.toString();
final TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
LOG.trace("Exception text (length={}): {}", exceptionText.length(), exceptionText);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
// final GridPane expandableContent = new GridPane();
// expandableContent.setMaxWidth( Double.MAX_VALUE );
//
// expandableContent.add( child, columnIndex, rowIndex );
alert.getDialogPane().setExpandableContent(textArea);
// alert.setResizable( true );
alert.showAndWait();
}
@Override
public void addFormForDisplayAccount() {
gridRowFrom = gridRow;
String countryCode = cashDepositAccountPayload.getCountryCode();
addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), paymentAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"),
Res.get(paymentAccount.getPaymentMethod().getId()));
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.country"),
getCountryBasedPaymentAccount().getCountry() != null ? getCountryBasedPaymentAccount().getCountry().name : "");
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null";
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"),
nameAndCode);
addHolderNameAndIdForDisplayAccount();
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.email"),
cashDepositAccountPayload.getHolderEmail());
if (BankUtil.isBankNameRequired(countryCode))
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.bank.name"),
cashDepositAccountPayload.getBankName()).second.setMouseTransparent(false);
if (BankUtil.isBankIdRequired(countryCode))
addCompactTopLabelTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(countryCode),
cashDepositAccountPayload.getBankId()).second.setMouseTransparent(false);
if (BankUtil.isBranchIdRequired(countryCode))
addCompactTopLabelTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(countryCode),
cashDepositAccountPayload.getBranchId()).second.setMouseTransparent(false);
if (BankUtil.isNationalAccountIdRequired(countryCode))
addCompactTopLabelTextField(gridPane, ++gridRow, BankUtil.getNationalAccountIdLabel(countryCode),
cashDepositAccountPayload.getNationalAccountId()).second.setMouseTransparent(false);
if (BankUtil.isAccountNrRequired(countryCode))
addCompactTopLabelTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(countryCode),
cashDepositAccountPayload.getAccountNr()).second.setMouseTransparent(false);
if (BankUtil.isAccountTypeRequired(countryCode))
addCompactTopLabelTextField(gridPane, ++gridRow, BankUtil.getAccountTypeLabel(countryCode),
cashDepositAccountPayload.getAccountType()).second.setMouseTransparent(false);
String requirements = cashDepositAccountPayload.getRequirements();
boolean showRequirements = requirements != null && !requirements.isEmpty();
if (showRequirements) {
TextArea textArea = addCompactTopLabelTextArea(gridPane, ++gridRow, Res.get("payment.extras"), "").second;
textArea.setMinHeight(30);
textArea.setMaxHeight(30);
textArea.setEditable(false);
textArea.setId("text-area-disabled");
textArea.setText(requirements);
}
addLimitations(true);
}
@Override
public void addFormForAddAccount() {
accountNrInputTextFieldEdited = false;
gridRowFrom = gridRow + 1;
Tuple2<ComboBox<TradeCurrency>, Integer> tuple = GUIUtil.addRegionCountryTradeCurrencyComboBoxes(gridPane, gridRow, this::onCountrySelected, this::onTradeCurrencySelected);
currencyComboBox = tuple.first;
gridRow = tuple.second;
addHolderNameAndId();
nationalAccountIdInputTextField = addInputTextField(gridPane, ++gridRow, BankUtil.getNationalAccountIdLabel(""));
nationalAccountIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
cashDepositAccountPayload.setNationalAccountId(newValue);
updateFromInputs();
});
bankNameInputTextField = addInputTextField(gridPane, ++gridRow, Res.get("payment.bank.name"));
bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
cashDepositAccountPayload.setBankName(newValue);
updateFromInputs();
});
bankIdInputTextField = addInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
cashDepositAccountPayload.setBankId(newValue);
updateFromInputs();
});
branchIdInputTextField = addInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
cashDepositAccountPayload.setBranchId(newValue);
updateFromInputs();
});
accountNrInputTextField = addInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
cashDepositAccountPayload.setAccountNr(newValue);
updateFromInputs();
});
accountTypeComboBox = addComboBox(gridPane, ++gridRow, Res.get("payment.select.account"));
accountTypeComboBox.setOnAction(e -> {
if (BankUtil.isAccountTypeRequired(cashDepositAccountPayload.getCountryCode())) {
cashDepositAccountPayload.setAccountType(accountTypeComboBox.getSelectionModel().getSelectedItem());
updateFromInputs();
}
});
TextArea requirementsTextArea = addTextArea(gridPane, ++gridRow, Res.get("payment.extras"));
requirementsTextArea.setMinHeight(30);
requirementsTextArea.setMaxHeight(90);
requirementsTextArea.textProperty().addListener((ov, oldValue, newValue) -> {
cashDepositAccountPayload.setRequirements(newValue);
updateFromInputs();
});
addLimitations(false);
addAccountNameTextFieldWithAutoFillToggleButton();
updateFromInputs();
}