Java Reference
In-Depth Information
private Product product;
private ChangeListener<String> listener;
public void setProduct(Product product) {
if (this.product != null) {
unhookListener();
}
this.product = product;
hookTo(product);
}
private void unhookListener() {
description.textProperty().removeListener(listener);
}
private void hookTo(Product product) {
if (product == null) {
category.setText("");
name.setText("");
description.setText("");
listener = null;
} else {
category.setText(product.getCategory());
name.setText(product.getName());
description.setText(product.getDescription());
listener = (observable, oldValue, newValue) ->
product.setDescription(newValue);
description.textProperty().addListener(listener);
}
}
}
Listing 3-24. IncludeExample.java
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class IncludeExample extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(
IncludeExample.class.getResource("IncludeExampleTree.fxml"));
final BorderPane borderPane = fxmlLoader.load();
Scene scene = new Scene(borderPane, 600, 400);
primaryStage.setTitle("Include Example");
primaryStage.setScene(scene);
primaryStage.show();
}
Search WWH ::




Custom Search