6. Node subnode = parentNode.lookup(“......”);
where .... is a CSS selector
Lets you quickly and easily get any descendent node.
Useful Selectors:
“#NodeID” find descendent node with id “NodeID”
“.StyleClass”
“ClassName”
LOOKUP
7. public class Lookup extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override public void start(Stage primaryStage) {
final SplitPane splitPane = new SplitPane();
splitPane.getItems().addAll(
RegionBuilder.create().style(
-fx-background-color: red;).build(),
RegionBuilder.create().style(
-fx-background-color: dodgerblue;).build()
);
Scene scene = new Scene(splitPane, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
}
8. public class Lookup extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override public void start(Stage primaryStage) {
final SplitPane splitPane = new SplitPane();
splitPane.getItems().addAll(
RegionBuilder.create().style(-fx-background-color: red;).build(),
RegionBuilder.create().style(-fx-background-color: dodgerblue;).build()
);
Scene scene = new Scene(splitPane, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
Pane gripper = (Pane)splitPane.lookup(.horizontal-grabber);
gripper.getChildren().add(
VBoxBuilder.create().spacing(5).children(
ButtonBuilder.create().text()
.onAction(new EventHandlerActionEvent() {
public void handle(ActionEvent t) {
splitPane.setDividerPosition(0, 0);
}
}).build(),
// .... a second button here for
).build()
);
splitPane.lookup(.split-pane-divider).setStyle(-fx-padding: 8px;);
}
}
16. public ToolBar createToolBar(String id) {
return ToolBarBuilder.create()
.id(id)
.items(
new Button(Button 1),
new Button(Button 2),
new Slider(),
new ChoiceBox(
FXCollections.observableArrayList(Font.getFamilies())),
new Button(Button 3)
).build();
}
CSS COLORING CONTROLS
Method for creating example ToolBar
17. public class DarkToolbar extends Application {
public static void main(String[] args) {
Application.launch(args);
}
public ToolBar createToolBar(String id) {.....}
@Override public void start(Stage primaryStage) {
primaryStage.setTitle(Colored Toolbars);
ToolBar standardToolbar = createToolBar(standard);
ToolBar darkToolbar = createToolBar(dark);
ToolBar blueToolbar = createToolBar(blue);
Scene scene = new Scene(
VBoxBuilder.create()
.spacing(10)
.padding(new Insets(10))
.children(standardToolbar, darkToolbar, blueToolbar)
.build()
);
scene.getStylesheets().add(
DarkToolbar.class.getResource(DarkToolbar.css).toString());
primaryStage.setScene(scene);
primaryStage.show();
}
}
23. Scene scene = new Scene(
VBoxBuilder.create()
.spacing(10)
.padding(new Insets(10))
.children(
ButtonBuilder.create()
.text(Inset Text Button)
.id(button1).build(),
LabelBuilder.create()
.text(Label styled as bar)
.id(label1).build()
)
.build()
);
CSS INSET TEXT
Apple style inset text, eg:
26. ANIMATION CACHING
When animating objects with complex graphics such as large
screens of controls like a data form can be jerky. So what
you need to do is cache them while animating.
31. BINDING
Using the low level binding API, you can do arbitrarily
interesting binding, such as creating complex messages
32. THE SETUP
StringBinding
• Listens to the TextField
• Computes the String to be
displayed in the Label
• Uses a SimpleDateFormat and
some Calendar’s to do the job
TextField
• Enter the text here
Label
• Just binds to a custom binding
40. VALIDATORS
Using the scene graph and some CSS you can wrap any
control in order to handle custom validation
41. Has-a
THE SETUP
TextInputValidatorPane
• A layout container which wraps its content
• Listens to changes in the TextField and
handles validation
• Sets the style class to “.validation-error” or
“.validation-warning” when there are
validation problems
Validator
• Interface which takes a control and
produces aValidationResult
ValidationResult
• Has a message validation result
type (Error,Warning, Normal)
CSS
• Styles make the background of the
text field change
TextField
• Just lives its life normal, doesn’t
have to do anything special
Styles
Creates
42.
43. TABLE PLACE HOLDER
You can place any node in as a place holder on aTableView
and it will be shown when there is no data.
44.
45. final TableView tableView = new TableView();
TABLE PLACE HOLDER
tableView.getColumns().addAll(
TableColumnBuilder.create()
.text(First)
.cellValueFactory(new PropertyValueFactory(firstName))
.build(),
TableColumnBuilder.create()
.text(Last)
.cellValueFactory(new PropertyValueFactory(lastName))
.build(),
TableColumnBuilder.create()
.text(Email)
.prefWidth(220)
.cellValueFactory(new PropertyValueFactory(email))
.build()
);
47. TABLE PLACE HOLDER
PauseTransitionBuilder.create()
.duration(Duration.seconds(5))
.onFinished(new EventHandlerActionEvent() {
public void handle(ActionEvent t) {
tableView.setItems(FXCollections.observableArrayList(
new Person(Jacob, Smith,
jacob.smith@example.com ),
new Person(Isabella, Johnson,
isabella.johnson@example.com ),
new Person(Ethan, Williams,
ethan.williams@example.com ),
new Person(Emma, Jones,
emma.jones@example.com ),
new Person(Michael, Brown,
michael.brown@example.com )
));
}
})
.build().play();
48. SUBMIT PROGRESS
It is nice to give the user some feedback while we are
responding to their action.A quick neat way to do this for
a form submission is to add a ProgressIndicator to the
submit button.
52. SUBMIT PROGRESS
public class SalesForm {
@FXML private void cancelAction(final ActionEvent event) {}
@FXML private void saveAction(final ActionEvent event) {
// put progress indicator in save button to show user
// something is happening
Button saveButton = (Button)event.getSource();
ProgressIndicator pi = new ProgressIndicator();
pi.setPrefSize(14,14);
saveButton.setGraphic(pi);
}
}
53. IMAGE BARCHART
You can customize the look of JavaFX charts with CSS
such as styling the bars of a BarChart with images.
54. IMAGE BARCHART
You can customize the look of JavaFX charts with CSS
such as styling the bars of a BarChart with images.
55.
56. IMAGE BARCHART
public class ImageBarChart extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override public void start(Stage primaryStage) {
primaryStage.setTitle(Image BarChart);
BarChart barChart = new BarChart(new CategoryAxis(), new NumberAxis());
barChart.setLegendVisible(false);
barChart.getData().add(
new XYChart.SeriesString,Integer(Sales Per Product,
FXCollections.observableArrayList(
new XYChart.DataString, Integer(SUV,120),
new XYChart.DataString, Integer(Sedan,50),
new XYChart.DataString, Integer(Truck,180),
new XYChart.DataString, Integer(Van,20)
)
)
);
Scene scene = new Scene(barChart, 350, 300);
scene.getStylesheets().add(InsetText.class
.getResource(ImageBarChart.css).toString());
primaryStage.setScene(scene);
primaryStage.show();
}
}
58. DRILL DOWN CHART
You can attach mouse handling to items in a chart so you
can do drill down or other actions.
59.
60. DRILL DOWN CHART
public class DrilldownChart extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override public void start(Stage primaryStage) {
primaryStage.setTitle(Drilldown Chart);
PieChart.Data A,B,C,D;
final PieChart pie = new PieChart(
FXCollections.observableArrayList(
A = new PieChart.Data(A, 20),
B = new PieChart.Data(B, 30),
C = new PieChart.Data(C, 10),
D = new PieChart.Data(D, 40)
)
);
Scene scene = new Scene(pie, 350, 300);
scene.getStylesheets().add(InsetText.class
.getResource(DrilldownChart.css).toString());
primaryStage.setScene(scene);
primaryStage.show();
}
}
61. DRILL DOWN CHART
public class DrilldownChart extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override public void start(Stage primaryStage) {
primaryStage.setTitle(Drilldown Chart);
PieChart.Data A,B,C,D;
final PieChart pie = new PieChart(
FXCollections.observableArrayList(
A = new PieChart.Data(A, 20),
B = new PieChart.Data(B, 30),
C = new PieChart.Data(C, 10),
D = new PieChart.Data(D, 40)
)
);
A.getNode().setOnMouseClicked(new EventHandlerMouseEvent() {
public void handle(MouseEvent t) {
pie.setData(FXCollections.observableArrayList(
new PieChart.Data(a1, 7),
new PieChart.Data(a2, 2),
new PieChart.Data(a3, 5),
new PieChart.Data(a4, 3),
new PieChart.Data(a5, 2)
));
}
});
Scene scene = new Scene(pie, 350, 300);
scene.getStylesheets().add(InsetText.class
.getResource(DrilldownChart.css).toString());
primaryStage.setScene(scene);
primaryStage.show();
}
}
72. The preceding is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into
any contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.The
development, release, and timing of any features or
functionality described for Oracle’s products
remains at the sole discretion of Oracle.