JavaFX/Classes/css/user/ContainerScrollStyleSheet.java

42 lines
1.2 KiB
Java
Raw Permalink Normal View History

package Classes.css.user;
import Classes.css.core.Context;
import Classes.css.core.Ruleset;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Bounds;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.FlowPane;
public class ContainerScrollStyleSheet{
/* Builds all necessary CSS/layout rules */
public ContainerScrollStyleSheet(Node target) throws Exception{
/* (1) Set rules */
Ruleset.load(target)
.add("top", Context.getInt("header-height") )
.add("left", Context.getInt("submenu-width") + Context.getInt("menu-width") - 3)
.add("right", 0)
// .add("pref-height", )
.apply();
/* (2) Manage dynamic 1st children bounds to it */
ScrollPane spane = (ScrollPane) target;
spane.layoutBoundsProperty().addListener(new ChangeListener(){
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
FlowPane child = (FlowPane) spane.getContent();
child.setPrefWidth( spane.getLayoutBounds().getWidth() );
child.setPrefHeight( spane.getLayoutBounds().getHeight() );
}
});
}
}