Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I set the controller in the scene builder?

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

like image 463
Delsa Avatar asked Dec 06 '16 11:12

Delsa


People also ask

How do I set Controller class in FXML?

There are two ways to set a controller for an FXML file. The first way to set a controller is to specify it inside the FXML file. The second way is to set an instance of the controller class on the FXMLLoader instance used to load the FXML document.

What is controller in JavaFX?

JavaFX controller works based on MVC(Model-View-Controller) JavaFX MVC can be achieved by FXML (EFF-ects eXtended Markup Language). FXML is an XML based language used to develop the graphical user interfaces for JavaFX applications as in the HTML.


1 Answers

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.

like image 170
James_D Avatar answered Oct 17 '22 22:10

James_D