Skip to content

Instantly share code, notes, and snippets.

View dlemmermann's full-sized avatar

Dirk Lemmermann dlemmermann

View GitHub Profile
@dlemmermann
dlemmermann / ShadowScrollPane.java
Created June 19, 2018 09:08
A JavaFX ScrollPane with a drop shadow effect at the top when the user scrolls down.
package uk.co.senapt.desktop.shell;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Region;
import javafx.scene.shape.Rectangle;
private void applyClip() {
ReadOnlyObjectProperty<Bounds> boundsProperty = layoutBoundsProperty();
Rectangle rect = new Rectangle();
rect.setManaged(false);
rect.layoutXProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getMinX(), boundsProperty));
rect.layoutYProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getMinY(), boundsProperty));
rect.widthProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getWidth(), boundsProperty));
rect.heightProperty().bind(Bindings.createDoubleBinding(() -> boundsProperty.get().getHeight(), boundsProperty));
rect.setFill(Color.BLACK);
@dlemmermann
dlemmermann / MaskedView.java
Last active August 28, 2018 08:25
This code shows how you can use clipping in JavaFX in combination with the alpha channel to implement fade in / out effects (not animations).
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.Skin;
public class MaskedView extends Control {
public MaskedView(Node content) {
@dlemmermann
dlemmermann / VisibleManagedDemo.java
Created June 18, 2018 08:51
A little demo showing how the "visible" and "managed" property can be used to make a node disappear in such a way that the layout pane / container can reclaim the space previously occupied by the now invisible node.
package uk.co.senapt.desktop;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;