java - Setting JavaFX Anchor Pane's anchors in CSS -
one of windows in gui application consists of similar hboxes same controls inside. wanted center in top layer pane (in case - anchor pane).
here's code:
<?xml version="1.0" encoding="utf-8"?> <?import javafx.scene.layout.anchorpane?> <?import javafx.scene.control.label?> <?import javafx.scene.layout.vbox?> <?import javafx.scene.layout.hbox?> <?import javafx.scene.control.textfield?> <?import javafx.scene.control.button?> <anchorpane xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"> <vbox fx:id="modewindowpane" alignment="center" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <hbox alignment="center" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <children> <label contentdisplay="center" maxheight="1.7976931348623157e308" prefwidth="100.0" text="current" /> <textfield prefwidth="100.0" /> <button maxheight="1.7976931348623157e308" mnemonicparsing="false" text="set current"/> </children> </hbox> <hbox alignment="center" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <children> <label contentdisplay="center" maxheight="1.7976931348623157e308" prefwidth="100.0" text="frequency" /> <textfield prefwidth="100.0" /> <button maxheight="1.7976931348623157e308" mnemonicparsing="false" text="set current"/> </children> </hbox> <hbox alignment="center" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <children> <label contentdisplay="center" maxheight="1.7976931348623157e308" prefwidth="100.0" text="fade in" /> <textfield prefwidth="100.0" /> <button maxheight="1.7976931348623157e308" mnemonicparsing="false" text="set current"/> </children> </hbox> <hbox alignment="center" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <children> <label contentdisplay="center" maxheight="1.7976931348623157e308" prefwidth="100.0" text="fade out" /> <textfield prefwidth="100.0" /> <button maxheight="1.7976931348623157e308" mnemonicparsing="false" text="set current"/> </children> </hbox> <hbox alignment="center" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <children> <label contentdisplay="center" maxheight="1.7976931348623157e308" prefwidth="100.0" text="offset" /> <textfield prefwidth="100.0" /> <button maxheight="1.7976931348623157e308" mnemonicparsing="false" text="set current"/> </children> </hbox> <hbox alignment="center" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <label contentdisplay="center" maxheight="1.7976931348623157e308" prefwidth="100.0" text="stimulation time" /> <textfield prefwidth="100.0" /> <button maxheight="1.7976931348623157e308" mnemonicparsing="false" text="set current"/> </hbox> </vbox> </anchorpane>
you can see in every hbox there bottom/left/right/top anchors. wanted parametrize them somehow, set default hbox properties in fxml file via css example. when started looking more info (tutorials, oracle's references, stack) didn't find useful.
can tell me if there way wouldn't have edit every component to, example, align in way want? also, has compliant mvc design pattern.
take @ javafx css reference guide. there find complete documentary of css attributes. far know can't set anchor's object via css.
you can make via controller. give items fx:id
assign them in controller. can iterate on them , set anchors (e.g. anchorpane.settopanchor(node, value)
). further information see anchorpane.
Comments
Post a Comment