javafx - Getting size of FXML generated nodes -
i want size of node, after has been sized properly, understand done after stage shown. however, cannot in start() method, because node not initialized yet, because loaded fxml file.
if implement initializable interface , try size in initialize() method, returns 0.0
<?xml version="1.0" encoding="utf-8"?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.borderpane?> <gridpane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="musicplayer.test"> <columnconstraints> <columnconstraints hgrow="sometimes" minwidth="10.0" prefwidth="100.0" /> </columnconstraints> <rowconstraints> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> </rowconstraints> <children> <tableview fx:id="testnode"> <columns> <tablecolumn prefwidth="75.0" text="c1" /> <tablecolumn prefwidth="75.0" text="c2" /> </columns> </tableview> </children> </gridpane> just arbitrary node in grid pane generated scene builder
public class test extends application implements initializable { @fxml private tableview testnode; public void initialize(url location, resourcebundle resources) { //system.out.println(testnode.getwidth()); 0.0 } public void start(stage primarystage) throws exception { parent root = fxmlloader.load(getclass().getresource("test.fxml")); scene scene = new scene(root); primarystage.setscene(scene); primarystage.show(); //system.out.println(testnode.getwidth()); throws nullpointer exception } public static void main(string[] args) { launch(args); } } i've tried adding listener stage, still nullpointer exception. there way of getting size, without using sleeping thread?
Comments
Post a Comment