pane.getChildren().addAll(); not working in a scene javafx -


this code not allow line draw in window... have in fxml file simple pane fx:id of hi test things out. there no error, line doesn't appear. i've tried box , circle. need help, important project.

import java.net.url; import java.util.resourcebundle; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.layout.anchorpane; import javafx.scene.layout.borderpane; import javafx.scene.layout.pane; import javafx.scene.shape.line; import javafx.scene.scene; import javafx.scene.paint.color;  public class plotscenecontroller implements initializable {      @fxml     pane hi;      @override     public void initialize(url url, resourcebundle rb) {      line line = new line(0,0,10,110);         line.setstroke(color.black);         line.setstrokewidth(10);         hi.getchildren().addall(line);      }  } 

fxml file

<?xml version="1.0" encoding="utf-8"?>  <?import javafx.scene.shape.*?> <?import java.lang.*?> <?import java.net.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?>   <pane fx:id="hi" maxheight="-infinity" maxwidth="-infinity" minheight="- infinity" minwidth="-infinity" prefheight="400.0" prefwidth="600.0"  xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <children>  </children> </pane> 

main class, leads page button leads page i'm having trouble with.

public class main extends application {  stage firststage; scene loginbutton;  @override public void start(stage primarystage) throws exception {                   parent root = fxmlloader.load(getclass().getresource("main.fxml"));     firststage = primarystage;                       loginbutton = new scene(root, 900, 700);          primarystage.settitle("treatment data");                 primarystage.setscene(loginbutton);              primarystage.show();                         }  /**  * @param args command line arguments  */ public static void main(string[] args) {        //main class     launch(args);                       //launches application/window } 

}

you missed set controller class plotscenecontroller.java. set controller class in different 2 way using main class setcontroller() method or set controller class in left bottom side controller pane in scene builder screen.

using main

fxmlloader loader = new fxmlloader(getclass().getresource("main.fxml")); loader.setcontroller(new plotscenecontroller()); parent root = (parent) loader.load(); 

or using fxml

set controller class full package path below way

enter image description here


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -