Example usage for javafx.util Callback Callback

List of usage examples for javafx.util Callback Callback

Introduction

In this page you can find the example usage for javafx.util Callback Callback.

Prototype

Callback

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group(), 200, 200);
    ComboBox<String> myComboBox = new ComboBox<String>();
    myComboBox.getItems().addAll("A", "B", "C", "D", "E");
    myComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override/* ww  w . jav a  2 s  . com*/
        public ListCell<String> call(ListView<String> param) {
            final ListCell<String> cell = new ListCell<String>() {
                {
                    super.setPrefWidth(100);
                }

                @Override
                public void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        setText(item);
                        if (item.contains("A")) {
                            setTextFill(Color.RED);
                        } else if (item.contains("B")) {
                            setTextFill(Color.GREEN);
                        } else {
                            setTextFill(Color.BLACK);
                        }
                    } else {
                        setText(null);
                    }
                }
            };
            return cell;
        }
    });
    Group root = (Group) scene.getRoot();
    root.getChildren().add(myComboBox);
    stage.setScene(scene);
    stage.show();
}

From source file:caillou.company.clonemanager.gui.spring.SpringFxmlLoader.java

public static LoadingMojo load(String url, final String controllerClassName) {

    lastLoadedURL = url;//from  w ww. j  a v  a 2 s . c o m
    FXMLLoader loader = new FXMLLoader(MainApp.class.getResource(url), resourceBundle);
    loader.setControllerFactory(new Callback<Class<?>, Object>() {
        @Override
        public Object call(Class<?> clazz) {
            if (controllerClassName != null) {
                try {
                    return applicationContext.getBean(Class.forName(controllerClassName));
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(SpringFxmlLoader.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            return applicationContext.getBean(clazz);
        }
    });

    try {
        Parent parent = loader.load();
        LoadingMojo loadingMojo = new LoadingMojo();
        loadingMojo.setController(loader.getController());
        loadingMojo.setParent(parent);
        return loadingMojo;
    } catch (IOException ex) {
        Logger.getLogger(SpringFxmlLoader.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception exMain) {
        System.out.println("Error");
    }
    return null;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    VBox vbox = new VBox(20);
    Scene scene = new Scene(vbox, 400, 400);
    stage.setScene(scene);/*from ww w .j a  va2 s . com*/
    DatePicker startDatePicker = new DatePicker();
    DatePicker endDatePicker = new DatePicker();
    startDatePicker.setValue(LocalDate.now());
    final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
        @Override
        public DateCell call(final DatePicker datePicker) {
            return new DateCell() {
                @Override
                public void updateItem(LocalDate item, boolean empty) {
                    super.updateItem(item, empty);

                    if (item.isBefore(startDatePicker.getValue().plusDays(1))) {
                        setDisable(true);
                        setStyle("-fx-background-color: #EEEEEE;");
                    }
                }
            };
        }
    };
    endDatePicker.setDayCellFactory(dayCellFactory);
    endDatePicker.setValue(startDatePicker.getValue().plusDays(1));
    vbox.getChildren().add(new Label("Start Date:"));
    vbox.getChildren().add(startDatePicker);
    vbox.getChildren().add(new Label("End Date:"));
    vbox.getChildren().add(endDatePicker);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    VBox vbox = new VBox(20);
    Scene scene = new Scene(vbox, 400, 400);
    stage.setScene(scene);/*from   ww w. ja v  a  2s  . c o m*/
    final DatePicker startDatePicker = new DatePicker();
    DatePicker endDatePicker = new DatePicker();
    startDatePicker.setValue(LocalDate.now());
    final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
        @Override
        public DateCell call(final DatePicker datePicker) {
            return new DateCell() {
                @Override
                public void updateItem(LocalDate item, boolean empty) {
                    super.updateItem(item, empty);

                    long p = ChronoUnit.DAYS.between(startDatePicker.getValue(), item);
                    setTooltip(new Tooltip("You're about to stay for " + p + " days"));
                }
            };
        }
    };
    endDatePicker.setDayCellFactory(dayCellFactory);
    endDatePicker.setValue(startDatePicker.getValue().plusDays(1));
    vbox.getChildren().add(new Label("Start Date:"));
    vbox.getChildren().add(startDatePicker);
    vbox.getChildren().add(new Label("End Date:"));
    vbox.getChildren().add(endDatePicker);
    stage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);
    GridPane gridpane = new GridPane();
    ComboBox<Color> cmb = new ComboBox<Color>();
    cmb.getItems().addAll(Color.RED, Color.GREEN, Color.BLUE);
    cmb.setCellFactory(new Callback<ListView<Color>, ListCell<Color>>() {
        @Override// w w w  .  j av  a 2 s . co m
        public ListCell<Color> call(ListView<Color> p) {
            return new ListCell<Color>() {
                private final Rectangle rectangle;
                {
                    setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                    rectangle = new Rectangle(10, 10);
                }

                @Override
                protected void updateItem(Color item, boolean empty) {
                    super.updateItem(item, empty);

                    if (item == null || empty) {
                        setGraphic(null);
                    } else {
                        rectangle.setFill(item);
                        setGraphic(rectangle);
                    }
                }
            };
        }
    });

    gridpane.add(cmb, 2, 0);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);

    primaryStage.show();
}

From source file:Main.java

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 300, Color.WHITE);

    GridPane gridpane = new GridPane();

    ComboBox<Color> cmb = new ComboBox<Color>();
    cmb.getItems().addAll(Color.RED, Color.GREEN, Color.BLUE);

    cmb.setCellFactory(new Callback<ListView<Color>, ListCell<Color>>() {
        @Override//w  ww.  j  ava 2s .  c o m
        public ListCell<Color> call(ListView<Color> p) {
            return new ListCell<Color>() {
                private final Rectangle rectangle;
                {
                    setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                    rectangle = new Rectangle(10, 10);
                }

                @Override
                protected void updateItem(Color item, boolean empty) {
                    super.updateItem(item, empty);

                    if (item == null || empty) {
                        setGraphic(null);
                    } else {
                        rectangle.setFill(item);
                        setGraphic(rectangle);
                    }
                }
            };
        }
    });

    gridpane.add(cmb, 2, 0);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);

    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

    ComboBox emailComboBox = new ComboBox();
    emailComboBox.getItems().addAll("A", "B", "C", "D", "E");
    emailComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override// w w w . ja v a 2s . c  om
        public ListCell<String> call(ListView<String> param) {
            final ListCell<String> cell = new ListCell<String>() {
                {
                    super.setPrefWidth(100);
                }

                @Override
                public void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        setText(item);
                        if (item.contains("A")) {
                            setTextFill(Color.RED);
                        } else if (item.contains("B")) {
                            setTextFill(Color.GREEN);
                        } else {
                            setTextFill(Color.BLACK);
                        }
                    } else {
                        setText(null);
                    }
                }
            };
            return cell;
        }

    });

    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(emailComboBox, 1, 0);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();

}

From source file:info.gianlucacosta.helios.fx.fxml.SpringFXMLLoader.java

public SpringFXMLLoader() {
    setControllerFactory(new Callback<Class<?>, Object>() {
        @Override/*from   www  . ja v a2s  .  c o  m*/
        public Object call(Class<?> requestedControllerClass) {
            return context.getBean(requestedControllerClass);
        }

    });
}

From source file:com.panemu.tiwulfx.table.LookupColumn.java

public LookupColumn(String propertyName, String lookupPropertyName, double prefWidth) {
    super(propertyName, prefWidth);
    this.lookupPropertyName = lookupPropertyName;
    setCellFactory(new Callback<TableColumn<R, C>, TableCell<R, C>>() {
        @Override/*from  ww  w  .  j a  va 2  s  .c o m*/
        public TableCell<R, C> call(TableColumn<R, C> p) {
            return new LookupTableCell<R, C>(LookupColumn.this);
        }
    });
    setStringConverter(stringConverter);
}

From source file:de.tmosebach.mm.jfxui.SpringFXMLLoader.java

public Node load(URL url) {
    try {//from ww  w. ja v  a  2s .  com
        FXMLLoader loader = new FXMLLoader(url);
        loader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> aClass) {
                return context.getBean(aClass);
            }
        });
        return loader.load();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(String.format("Failed to load FXML file '%s'", url));
    }
}