java - JavaFX fade out stage and close -
i'm having difficulty finding out if possible. common behavior people want fade out extension of node
, entirely possible through fadetransition
however, i'm trying fade out entire stage, imagine closing running program , instead of killing windows (i.e. showing -> not showing), window (stage
) fade out on 2 seconds toast or notification would.
create timeline keyframe changes opacity of stage's scene's root node. make sure set stage style , scene fill transparent. make program exit once timeline finished.
below application single big button that, when clicked, take 2 seconds fade away, , program close.
public class stagefadeexample extends application { @override public void start(stage arg0) throws exception { stage stage = new stage(); stage.initstyle(stagestyle.transparent); //removes window decorations button close = new button("fade away"); close.setonaction((actionevent) -> { timeline timeline = new timeline(); keyframe key = new keyframe(duration.millis(2000), new keyvalue (stage.getscene().getroot().opacityproperty(), 0)); timeline.getkeyframes().add(key); timeline.setonfinished((ae) -> system.exit(1)); timeline.play(); }); scene scene = new scene(close, 300, 300); scene.setfill(color.transparent); //makes scene background transparent stage.setscene(scene); stage.show(); } public static void main (string[] args) { launch(); } }
Comments
Post a Comment