java - Layout using the transformed bounds -
i have scaled node in pane. layout of pane take account bounds without transformation. want take account transformed bounds.
for example :
and code :
import javafx.application.application; import javafx.geometry.pos; import javafx.scene.scene; import javafx.scene.control.label; import javafx.scene.layout.hbox; import javafx.scene.layout.vbox; import javafx.scene.shape.circle; import javafx.scene.transform.scale; import javafx.scene.transform.translate; import javafx.stage.stage; public class hboxapp extends application { public static void main(string[] args) { launch(args); } @override public void start(stage stage) throws exception { double scale = 0.75; hbox box1 = createbox(); box1.getchildren().add(new circle(20)); box1.getchildren().add(new label("test without scale")); hbox box2 = createbox(); circle c2 = new circle(20); c2.setscalex(scale); c2.setscaley(scale); box2.getchildren().add(c2); box2.getchildren().add(new label("test setscalex/y methods")); hbox box3 = createbox(); circle c3 = new circle(20); c3.gettransforms().add(new scale(scale, scale)); box3.getchildren().add(c3); box3.getchildren().add(new label("test scale transform")); hbox box4 = createbox(); circle c4 = new circle(20); c4.gettransforms().addall(new scale(scale, scale), new translate(-20*(1-scale), 0)); box4.getchildren().add(c4); box4.getchildren().add(new label("test scale , translate transform")); hbox box5 = createbox(); box5.getchildren().add(new circle(20 * scale)); box5.getchildren().add(new label("my goal")); vbox vbox = new vbox(10); vbox.getchildren().addall(box1, box2, box4, box5); stage.setscene(new scene(vbox, 300, 200)); stage.show(); } private hbox createbox() { hbox box = new hbox(5); box.setalignment(pos.center_left); return box; } }
a solution apply translations on circle , on label, way seems hard doing simple thing, , using pane
(hbox
) seems more painful using basic group
hardcoded layout.
i found answer in post javafx1.2: understanding bounds :
if want layoutbounds match node's physical bounds (including effects, clip, , transforms) wrap in group (ex. if want node scale on mouse-over , want neighbors scoot on make room magnified node).
so solving problem, wrote :
... hbox box5 = createbox(); circle c5 = new circle(20); c5.setscalex(scale); c5.setscaley(scale); box5.getchildren().add(new group(c5)); box5.getchildren().add(new label("test scale transform , group")); ...
and got expected result.
Comments
Post a Comment