Search code examples
javafxcolorsinverse

JavaFx Inverse Color of stage


It is possible to inverse the color of the whole stage/scene? Maybe via CSS or method? I want avoid to style every element in the stage.


Solution

  • If you only want to apply this effect on the scene, you could use a Blend effect that blends the scene with a mode of DIFFERENCE and uses white as bottom input on the root node:

    ColorInput color = new ColorInput();
    color.setPaint(Color.WHITE);
    color.setWidth(Double.MAX_VALUE);
    color.setHeight(Double.MAX_VALUE);
    
    Blend blend = new Blend(BlendMode.DIFFERENCE);
    blend.setBottomInput(color);
    
    root.setEffect(blend); // apply effect on scene root
    

    Unfortunately you cannot create these kinds of effects from CSS.