Javafx Tutorial: Tom Schindl
Javafx Tutorial: Tom Schindl
‣ Eclipse Committer
‣ e4
‣ Platform
‣ EMF
‣ Project lead
‣ e(fx)clipse
primaryStage.setScene(scene);
primaryStage.show(); Display
primaryStage.setScene(scene);
primaryStage.show(); Display
public static void main(String[] args) {
launch(args); inherited method
}
Montag, 28. Oktober 13
Lab HelloWorld
‣ Setting up Eclipse
‣ Install JDK8u112
‣ Select: Finish
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World via setOnAction!");
}
});
b.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World via addEventHandler!");
}
});
root.setCenter(b);
‣ get$Name$/set$Name$ method
‣ $name$Property method
‣ property-method returns
‣ read/writable: javafx.beans.property.Property
‣ readonly: javafx.beans.property.ReadOnlyProperty
}
}
‣ Unidirectional: Property#bind()
‣ Bidirectional: Property#bindBidirectional()
‣ Unlink bindings:
‣ Unidirectional: Property#unbind()
‣ Bidirectional: Property#unbindBirectional()
‣ Name: MyBean
‣ top: javafx.scene.control.TextField
‣ center: javafx.scene.text.Text
‣ right: javafx.scene.control.Slider
‣ Bind:
‣ unidirectional:
‣ MyBean#text to Text#text
‣ H-Slider#value to Text#scaleX
‣ V-Slider#value to Text#scaleY
‣ Make sure the sliders are only modifiable when the text
field has a value entered
‣ javafx.scene.layout.BorderPane
‣ javafx.scene.layout.HBox
‣ javafx.scene.layout.VBox
‣ javafx.scene.layout.GridPane
‣ Additional layouts
‣ org.eclipse.fx.ui.panes.GridLayoutPane
‣ org.eclipse.fx.ui.panes.FillLayoutPane
‣ org.eclipse.fx.ui.panes.RowLayoutPane
‣ MigPane (http://www.miglayout.com/)
‣ Executing actions
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<HBox xmlns:fx="http://javafx.com/fxml"
fx:controller="application.SampleController">
<children>
<Button
fx:id="mybutton"
text="Hello World"
onAction="#run">
</Button>
</children>
</HBox>
‣ Executing actions
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<HBox xmlns:fx="http://javafx.com/fxml"
fx:controller="application.SampleController"> Java-Class
<children>
<Button
fx:id="mybutton"
text="Hello World"
onAction="#run">
</Button>
</children>
</HBox>
‣ Executing actions
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<HBox xmlns:fx="http://javafx.com/fxml"
fx:controller="application.SampleController"> Java-Class
<children>
<Button
fx:id="mybutton" Field in class
text="Hello World"
onAction="#run">
</Button>
</children>
</HBox>
‣ Executing actions
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<HBox xmlns:fx="http://javafx.com/fxml"
fx:controller="application.SampleController"> Java-Class
<children>
<Button
fx:id="mybutton" Field in class
text="Hello World"
onAction="#run">
</Button>
Method in class
</children>
</HBox>
‣ layout-constraint support
‣ i18n support
‣ Connect to controller
‣ Use i18n
‣ Language: FXML
‣ Root-Type: javafx.scene.layout.BorderPane
‣ Filename: Sample
‣ Open Preview using Window > Show View > JavaFX > JavaFX
Preview
‣ Create a messages.properties-File
‣ Definitions:
‣ Object-Def: Button { }
import javafx.scene.layout.BorderPane
import application.SampleController
import javafx.scene.control.Button
import javafx.scene.layout.BorderPane
import application.SampleController
import javafx.scene.control.Button
import javafx.scene.layout.BorderPane
import application.SampleController
import javafx.scene.control.Button
import javafx.scene.layout.BorderPane
import application.SampleController
import javafx.scene.control.Button
‣ Layout-constraint support:
‣ i18n support
‣ media support:
‣ preview marker:
Field in class
‣ Connect to controller
‣ Use i18n
‣ Language: FXGraph
‣ Root-Type: javafx.scene.layout.BorderPane
‣ Filename: Currency
‣ Create the UI
‣ add a javafx.scene.control.TextField
‣ add a javafx.scene.control.TextField
‣ ListView as currencyList
SceneGraph
BorderPane
TitledPane
SceneGraph
BorderPane
TitledPane
StackPane
HBox
Label
StackPane
StackPane
SceneGraph
BorderPane logical scenegraph
TitledPane
StackPane
HBox
Label
StackPane
StackPane
SceneGraph
BorderPane logical scenegraph
TitledPane
StackPane
HBox
Label full scenegraph
StackPane
StackPane
@Override
public ListCell<Currency> call(ListView<Currency> param) {
return new CurrencyCell();
}
});
JDK7-Style
currencyList.setCellFactory(new Callback<ListView<Currency>, ListCell<Currency>>() {
@Override
public ListCell<Currency> call(ListView<Currency> param) {
return new CurrencyCell();
}
});
JDK7-Style
currencyList.setCellFactory(new Callback<ListView<Currency>, ListCell<Currency>>() {
@Override
public ListCell<Currency> call(ListView<Currency> param) {
return new CurrencyCell();
}
});
‣ JavaBeanProperties, EMFProperties
e.g. EMFProperties.value(MyfondPackage.Literals.CURRENCY__NAME);
‣ JavaBeanProperties, EMFProperties
e.g. EMFProperties.value(MyfondPackage.Literals.CURRENCY__NAME);
‣ JavaBeanProperties, EMFProperties
e.g. EMFProperties.value(MyfondPackage.Literals.CURRENCY__NAME);
‣ Creation of IObservableValue
‣ JavaBeanProperties, EMFProperties
e.g. EMFProperties.value(MyfondPackage.Literals.CURRENCY__NAME);
‣ Creation of IObservableValue
‣ simple: IValueProperty#observe(Object)
‣ JavaBeanProperties, EMFProperties
e.g. EMFProperties.value(MyfondPackage.Literals.CURRENCY__NAME);
‣ Creation of IObservableValue
‣ simple: IValueProperty#observe(Object)
‣ master-detail: IValueProperty#observeDetail(IObservableValue)
‣ In the initialize-method
‣ Ant integration
‣ Toolkit Type: fx
‣ Load an FXML-File
‣ Create a new project using File > New Project ... > OSGi
Application Project
‣ Bundle-ID-Prefix: osgi.sample
‣ Add a button
‣ Create a controller
@Inject
@FXMLLoader
FXMLLoaderFactory factory;
// ...
BorderPane pane = (BorderPane) factory.loadRequestorRelative("Sample.fxml").load();
@Override
public boolean check(Button arg0) {
return true;
}
});
‣ Each type is wrapped in a class named Wrap<T>
‣ Access the native control and check that the text has
changed
‣ Bundle-ID-Prefix: e4.sample
‣ On page 2
‣ org.eclipse.emf.ecore
‣ org.eclipse.emf.databinding
‣ Copy at.bestsolution.myfond.model_......jar to it
‣ In the lower right click add select the jar you copied
to libs
@Inject
@FXMLLoader
FXMLLoaderFactory factory;
@PostConstruct
void initUI(BorderPane pane) {
try {
pane.setCenter((Node) factory.loadRequestorRelative("Currency.fxml")
.resourceBundle(ResourceBundle.getBundle("application.messages"))
.load());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
‣ Layouts
‣ Canvas!
‣ Parts of StyledText
‣ CSS-Ref - http://docs.oracle.com/javafx/2/api/javafx/
scene/doc-files/cssref.html
‣ FXML-Ref: http://docs.oracle.com/javafx/2/api/javafx/fxml/
doc-files/introduction_to_fxml.html
‣ SceneBuilder: http://www.oracle.com/technetwork/java/
javafx/tools/default-1568085.html
‣ My Blog: http://tomsondev.bestsolution.at/