The only purpose of this class is to allow dragging and dropping an unfinished window. It also has responsibilities to ensure that the TaskBar remains visible with FullScreen and ensures that an undeclared window is not displayed. Finally, it provides a bug fix for the "css resource not found" error. Just paste the code below in the main class into the overridden start () method when the “READY” stage is displayed or after it.
WindowStyle.allowDrag(root, stage); WindowStyle.stageDimension(stage.getWidth(), stage.getHeight());
NOTE. Paste the above value if “Stage” should be set to “READY” for it to appear or after it. For a full screen window, use:
WindowStyle.fullScreen(Stage stage);
To resize previous use:
WindowStyle.restoreScreen(Stage stage);
To add custom stylesheets to your scene, simply paste the start () override method after defining your scene under the code in the main class.
scene.getStylesheets().add(WindowStyle.addStyleSheet(String css));
The css name that will be used for styling can be in the form: main.css or styles/main.css
import javafx.geometry.Rectangle2D; import javafx.scene.Parent; import javafx.scene.input.MouseEvent; import javafx.stage.Screen; import javafx.stage.Stage; public class WindowStyle { private static final Rectangle2D SCREEN_BOUNDS= Screen.getPrimary() .getVisualBounds(); private static double[] pref_WH, offset_XY; private static String styleSheet; private WindowStyle(String css) { styleSheet= getClass().getResource(css).toString(); } protected static void allowDrag(Parent root, Stage stage) { root.setOnMousePressed((MouseEvent p) -> { offset_XY= new double[]{p.getSceneX(), p.getSceneY()}; }); root.setOnMouseDragged((MouseEvent d) -> {
Benjamin wasula
source share