r/JavaFX • • Nov 10 '19

Controller class. Now what?

Total newbie here. So I have my @FXML IDs set up.

I have this:

public class Controller {

@FXML

private AnchorPane paneFoo;

}

I want to test if everything works right. I just want to print "Hello World" in that pane but nothing seems to work.

Thanks!

0 Upvotes

6 comments sorted by

2

u/Holothuroid Nov 11 '19

That description isn't very helpful. What exactly doesn't work?

Nothing works as in the app doesn't start? Do you have an App class with the proper call? Do you mention the controller in the fxml?

To manipulate the stage on startup you can put a void method called initialize() in your controller. You can use it to add a Label with Hello World to the pane. Or you just write it directly in the fxml. In that case you do not need the orange in the controller.

1

u/GaryBuseyWithRabies Nov 11 '19

I'll tell you my long term goal.

I have an excel spread sheet with my data. I want to create a generic form that repeats this form for every row in the the spreadsheet.

I am lost on how to make this happen.

2

u/AdminOfThis Nov 11 '19

Nothing works as in the app doesn't start? Do you have an App class with the proper call? Do you mention the controller in the fxml?

Would be helpful to answer those specific asked questions, otherwise it is hard to help

1

u/GaryBuseyWithRabies Nov 12 '19

I'm sorry that I didn't properly answer your questions. What doesn't work is just putting code in the controller class. I thought that I could change those statements under the @fxml into classes and write code directly into the panes I created.

I'm too green to answer your other questions. I pretty much let intellij set up the app.

1

u/AdminOfThis Nov 11 '19

Some additional Info would be great.

It's a "Controller". What do you want to control? An FXML File?

For a Text you need something like a Label. Does that already exist somewhere?

Do you already have code somewhere that starts the Application? How does it look?

Some general thoughts:

Controllers usually implement the Interface Initializable

You need to have a class that is a child of the JavaFX class Application.

Then, in your application child class, you can load the fxml file with your gui, and set that to a new Scene which goes to the Stage you get from the application methods. And finally you have to show the stage.

1

u/GaryBuseyWithRabies Nov 12 '19

Yes, I want to control the fxml file.

I understand a label but I want to make it a variable that gets created from a cell on the spreadsheet.