e(fx)clipse 1.1 – New features – Generate controller from FXML


Although we have a very feature rich FXML-Editor with a live preview many users are using SceneBuilder to define their UIs. In case you have an FXML you want the possibility to generate a controller who references:

  • elements marked with fx:id as fields
  • event handler properties like onAction="#login" as methods

e(fx)clipse 1.1.0 added a first version of a wizard who allows you to generate the controller from it (no merging yet!)

Let’s assume you have the following FXML-File

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.Button?>

<BorderPane xmlns:fx="http://javafx.com/fxml/1">
	<Button 
		fx:id="loginbutton"
		onAction="#login"></Button>
</BorderPane>

You can bring up the context menu on the editor and inside the Source-Menu you’ll find the “Generate Controller”-Action as showing in the screenshot

generate-controller

It will bring up a dialog like this:

generate-controller_2

and if you finish it a java class like this gets generated

package application;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.event.ActionEvent;

public class SampleController {
	@FXML
	private Button loginbutton;

	// Event Listener on Button[#loginbutton].onAction
	@FXML
	public void login(ActionEvent event) {
		// TODO Autogenerated
	}
}

Advertisements
This entry was posted in e(fx)clipse and tagged . Bookmark the permalink.

3 Responses to e(fx)clipse 1.1 – New features – Generate controller from FXML

  1. Pingback: e(fx)clipse 1.1.0 released | Tomsondev Blog

  2. Nate3294 says:

    When I do this, it generates the controller class, but I notice that public void login(ActionEvent event) {…, it generates public void login(? event) {…

    Also, it does “import ?;” Do you know why it might be using a question mark instead of ActionEvent?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s