Skip to content

Commit 3eefe11

Browse files
committed
Fixed: ShowMessage dialogs may display cropped messages #31
1 parent c0fdec6 commit 3eefe11

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

scalafx-extras/src/main/scala/org/scalafx/extras/ShowMessage.scala

+37-16
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,21 @@ trait ShowMessage {
211211
* @param header header text.
212212
* @param content main content text.
213213
*/
214-
def showError(title: String, header: String, content: String = ""): Unit = {
214+
def showError(title: String, header: String, content: String = "", resizable: Boolean = false): Unit = {
215215
messageLogger.foreach(_.error(s"<$title> $header $content"))
216216
// Rename to avoid name clashes
217-
val dialogTitle = title
217+
val _title = title
218+
val _resizable = resizable
218219

219220
onFXAndWait {
220221
new Alert(AlertType.Error) {
221222
initOwner(parentWindow.orNull)
222-
this.title = dialogTitle
223+
this.title = _title
223224
headerText = header
224225
contentText = content
226+
this.resizable = _resizable
227+
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
228+
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
225229
}.showAndWait()
226230
}
227231
}
@@ -248,18 +252,18 @@ trait ShowMessage {
248252
def showInformation(title: String, header: String, content: String, resizable: Boolean = false): Unit = {
249253
// messageLogger.info(s"<$title> $header $content")
250254
// Rename to avoid name clashes
251-
val dialogTitle = title
252-
255+
val _title = title
253256
val _resizable = resizable
254257

255258
onFXAndWait {
256259
new Alert(AlertType.Information) {
257260
initOwner(parentWindow.orNull)
258-
this.title = dialogTitle
261+
this.title = _title
259262
headerText = header
260263
contentText = content
261264
this.resizable = _resizable
262-
dialogPane().minHeight(Region.USE_PREF_SIZE)
265+
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
266+
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
263267
}.showAndWait()
264268
}
265269
}
@@ -271,17 +275,21 @@ trait ShowMessage {
271275
* @param header header text.
272276
* @param content main content text.
273277
*/
274-
def showWarning(title: String, header: String, content: String): Unit = {
278+
def showWarning(title: String, header: String, content: String, resizable: Boolean = false): Unit = {
275279
messageLogger.foreach(_.warn(s"<$title> $header $content"))
276280
// Rename to avoid name clashes
277-
val dialogTitle = title
281+
val _title = title
282+
val _resizable = resizable
278283

279284
onFXAndWait {
280285
new Alert(AlertType.Warning) {
281286
initOwner(parentWindow.orNull)
282-
this.title = dialogTitle
287+
this.title = _title
283288
headerText = header
284289
contentText = content
290+
this.resizable = _resizable
291+
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
292+
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
285293
}.showAndWait()
286294
}
287295
}
@@ -294,16 +302,20 @@ trait ShowMessage {
294302
* @param content content text.
295303
* @return `true` when user selected 'OK' and `false` when user selected `Cancel` or dismissed the dialog.
296304
*/
297-
def showConfirmation(title: String, header: String, content: String = ""): Boolean = {
305+
def showConfirmation(title: String, header: String, content: String = "", resizable: Boolean = false): Boolean = {
298306
// Rename to avoid name clashes
299-
val dialogTitle = title
307+
val _title = title
308+
val _resizable = resizable
300309

301310
val result = onFXAndWait {
302311
new Alert(AlertType.Confirmation) {
303312
initOwner(parentWindow.orNull)
304-
this.title = dialogTitle
313+
this.title = _title
305314
headerText = header
306315
contentText = content
316+
this.resizable = _resizable
317+
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
318+
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
307319
}.showAndWait()
308320
}
309321
result match {
@@ -321,16 +333,25 @@ trait ShowMessage {
321333
* @return `Some(true)` when user selected 'OK', `Some(false)` when user selected `No`,
322334
* and `None` user selected `Cancel` or dismissed the dialog.
323335
*/
324-
def showConfirmationYesNoCancel(title: String, header: String, content: String = ""): Option[Boolean] = {
336+
def showConfirmationYesNoCancel(
337+
title: String,
338+
header: String,
339+
content: String = "",
340+
resizable: Boolean = false
341+
): Option[Boolean] = {
325342
// Rename to avoid name clashes
326-
val dialogTitle = title
343+
val _title = title
344+
val _resizable = resizable
327345

328346
val result = onFXAndWait {
329347
new Alert(AlertType.Confirmation) {
330348
initOwner(parentWindow.orNull)
331-
this.title = dialogTitle
349+
this.title = _title
332350
headerText = header
333351
contentText = content
352+
this.resizable = _resizable
353+
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
354+
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
334355
buttonTypes = Seq(ButtonType.OK, ButtonType.No, ButtonType.Cancel)
335356
}.showAndWait()
336357
}

0 commit comments

Comments
 (0)