FXMLBuilder StackOverflowError [message #1723345] |
Sun, 14 February 2016 21:48 |
John Bodkin Messages: 39 Registered: November 2011 |
Member |
|
|
What is the correct way to load an FXML file in a e4 part?
The builder.load() method generates a StackOverflowError.
I created an e4 Application project from File->New->Project...->JavaFX->OSGI
I edited the @PostConstruct method to look like the following:
@PostConstruct
public void postConstruct(BorderPane parent, @FXMLLoader FXMLLoaderFactory factory) {
try {
FXMLBuilder<Node> builder = factory.loadRequestorRelative("IOS.fxml");
Node n = builder.load();
parent.setCenter(n);
} catch (IOException e) {
e.printStackTrace();
}
// This works when the FXML loader code is commented out.
// Button btn = new Button("Hello World");
// btn.setId("hwButton");
// btn.setOnAction(new EventHandler<ActionEvent>() {
// @Override
// public void handle(ActionEvent event) {
// System.out.println("Button clicked");
// }
// });
// parent.setCenter(btn);
}
The FXML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Do not edit this file it is generated by e(fx)clipse from ../src/com/parts/IOS.fxgraph
-->
<?import java.lang.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>
<?scenebuilder-stylesheet /css/default.css?>
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.parts.UIPart">
<center>
<Button fx:id="hwButton" text="Hello World" onAction="#clicked"/>
</center>
</BorderPane>
Thanks for the help,
John
[Updated on: Sun, 14 February 2016 21:50] Report message to a moderator
|
|
|
|
Re: FXMLBuilder StackOverflowError [message #1731152 is a reply to message #1723346] |
Tue, 03 May 2016 08:43 |
Eclipse User |
|
|
|
John Bodkin wrote on Sun, 14 February 2016 22:08I always manage to figure this stuff out after I ask for help.
You can't make the Part the Controller as well. I created another class that the FXML is controlled by and the e4 Part loaded as expected.
I'm still learning JavaFX in an e4 app.
I just ran into the same problem. Is this the preferred way of doing that? I tried to have the MPart be the controller as well. Is that even possible?
Or are you supposed to do it something like this (with MPart being registered somewhere in the application model):
public class MyPart {
Node view;
MyController controller;
@PostConstruct
void init(HBox p, IEclipseContext context) {
InjectingFXMLLoader<Node> iFXMLLoader = InjectingFXMLLoader.create(context, getClass(), "view.fxml");
try {
Data<Node, MyController> data = iFXMLLoader.loadWithController();
view = data.getNode();
controller = data.getController();
p.getChildren().add(view);
// ...do other stuff
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05012 seconds