Pārlūkot izejas kodu

:recycle: Improvement for issue #245, allow dialogs to wrap a user given node in a scroll pane

Alessadro Parisi 2 gadi atpakaļ
vecāks
revīzija
c27646a6f7

+ 9 - 1
materialfx/src/main/java/io/github/palexdev/materialfx/dialogs/MFXGenericDialog.java

@@ -222,12 +222,20 @@ public class MFXGenericDialog extends AbstractMFXDialog {
 		content.setWrapText(true);
 		content.getStyleClass().add("content");
 		content.textProperty().bind(contentTextProperty());
+		buildScrollableContent(content, smoothScrolling);
+	}
 
+	/**
+	 * Allows to set an arbitrary {@link Node} as content, wrapped in a {@link MFXScrollPane} to make it scrollable.
+	 *
+	 * @param content         the node inside the scroll pane
+	 * @param smoothScrolling to specify whether to use smooth scrolling on the {@link MFXScrollPane}
+	 */
+	protected void buildScrollableContent(Node content, boolean smoothScrolling) {
 		MFXScrollPane scrollPane = new MFXScrollPane(content);
 		scrollPane.getStyleClass().add("content-container");
 		scrollPane.setFitToWidth(true);
 		if (smoothScrolling) ScrollUtils.addSmoothScrolling(scrollPane, 0.5);
-
 		setContent(scrollPane);
 	}
 

+ 9 - 0
materialfx/src/main/java/io/github/palexdev/materialfx/dialogs/MFXGenericDialogBuilder.java

@@ -18,6 +18,7 @@
 
 package io.github.palexdev.materialfx.dialogs;
 
+import io.github.palexdev.materialfx.controls.MFXScrollPane;
 import javafx.event.EventHandler;
 import javafx.geometry.Orientation;
 import javafx.scene.Node;
@@ -159,6 +160,14 @@ public class MFXGenericDialogBuilder {
 		return this;
 	}
 
+	/**
+	 * Wraps the given content in a {@link MFXScrollPane} which will then be used as the dialog's content.
+	 */
+	public MFXGenericDialogBuilder makeScrollable(Node content, boolean smoothScrolling) {
+		dialog.buildScrollableContent(content, smoothScrolling);
+		return this;
+	}
+
 	/**
 	 * Adds the given style classes to the dialog.
 	 */