java - JavaFX 8: Stage insets (window decoration thickness)? -



java - JavaFX 8: Stage insets (window decoration thickness)? -

how can determine stage/window insets in javafx? in swing simple write:

class="lang-java prettyprint-override">jframe frame = new jframe(); insets insets = frame.getinsets();

what equivalent in javafx size of border , titlebar of window?

you can determine these looking @ bounds of scene relative width , height of window.

given scene scene;, scene.getx() , scene.gety() give x , y coordinates of scene within window. these equivalent left , top insets, respectively.

the right , bottom trickier, but

scene.getwindow().getwidth()-scene.getwidth()-scene.getx()

gives right insets, , similarly

scene.getwindow().getheight()-scene.getheight()-scene.gety()

gives bottom insets.

these values of course of study create sense 1 time scene placed in window , window visible on screen.

if want insets object can next (which remain valid if border or title bar changed size after window displayed):

import javafx.application.application; import javafx.beans.binding.bindings; import javafx.beans.binding.objectbinding; import javafx.geometry.insets; import javafx.geometry.pos; import javafx.scene.scene; import javafx.scene.control.label; import javafx.scene.layout.vbox; import javafx.stage.stage; public class windowinsetsdemo extends application { @override public void start(stage primarystage) { label toplabel = new label(); label leftlabel = new label(); label rightlabel = new label(); label bottomlabel = new label(); vbox root = new vbox(10, toplabel, leftlabel, bottomlabel, rightlabel); root.setalignment(pos.center); scene scene = new scene(root, 600, 400); objectbinding<insets> insets = bindings.createobjectbinding(() -> new insets(scene.gety(), primarystage.getwidth()-scene.getwidth() - scene.getx(), primarystage.getheight()-scene.getheight() - scene.gety(), scene.getx()), scene.xproperty(), scene.yproperty(), scene.widthproperty(), scene.heightproperty(), primarystage.widthproperty(), primarystage.heightproperty() ); toplabel.textproperty().bind(bindings.createstringbinding(() -> "top: "+insets.get().gettop(), insets)); leftlabel.textproperty().bind(bindings.createstringbinding(() -> "left: "+insets.get().getleft(), insets)); rightlabel.textproperty().bind(bindings.createstringbinding(() -> "right: "+insets.get().getright(), insets)); bottomlabel.textproperty().bind(bindings.createstringbinding(() -> "bottom: "+insets.get().getbottom(), insets)); primarystage.setscene(scene); primarystage.show(); } public static void main(string[] args) { launch(args); } }

java border javafx-8 stage window-decoration

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -