Java Reference
In-Depth Information
@FXML
private Button loadButton;
private String name;
public FXMLLoaderExampleController(String name) {
this.name = name;
}
@FXML
public void actionHandler() {
webView.getEngine().load(address.getText());
}
}
Listing 3-6. FXMLLoaderExampleMain.java
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class FXMLLoaderExampleMain extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(
FXMLLoaderExampleMain.class.getResource("/FXMLLoaderExample.fxml"));
fxmlLoader.setController(
new FXMLLoaderExampleController("FXMLLoaderExampleController"));
final VBox vBox = fxmlLoader.load();
Scene scene = new Scene(vBox, 600, 400);
primaryStage.setTitle("FXMLLoader Example");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Because we did not specify the fx:controller attribute in the top-level element of the FXML file, we need to set
the controller on fxmlLoader before loading the FXML file:
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(
FXMLLoaderExampleMain.class.getResource("/FXMLLoaderExample.fxml"));
fxmlLoader.setController(
new FXMLLoaderExampleController("FXMLLoaderExampleController"));
final VBox vBox = fxmlLoader.load();
 
Search WWH ::




Custom Search