how can I set the controller in the scene builder?

Delsa picture Delsa · Dec 6, 2016 · Viewed 21.6k times · Source

I want to use sceneBuilder for a javaFx application. I have a Package that is called testPac and inside that I have the folders as has been presented in figure 1;

figure 1

I have one fxml file and its controller inside the view folder. now, I don't know what I must use inside the controller box in sceneBuilder. the content of view folder according to figure 2.

figure 2

Answer

James_D picture James_D · Dec 6, 2016

You just need to specify the fully-qualified classname, i.e. packagename.ClassName. So, if I understand your project structure correctly, your controller class is scaterChartController1 and it is in a package called testPac.view1,2. So your fx:controller attribute should have the value fx:controller = "testPac.view.scaterChartController".

In SceneBuilder you can set this in the "Controller" pane which is in the bottom left of the screen (expand it if necessary):

enter image description here


Footnotes:

  1. You should follow proper naming conventions, so all class names should begin with an upper case letter. scaterChartController is not a proper class name according to the standard convention. Similarly, package names should be all lower case, so "a package called testPac" also violates the convention.
  2. The package name is evident from the first line of code. I am assuming you have a package name of view, so the first line of code in the controller class will be

    package testPac.view ;
    

    Modify the fx:controller attribute accordingly if the package is different to that.