Example usage for javafx.scene.control ListView setCellFactory

List of usage examples for javafx.scene.control ListView setCellFactory

Introduction

In this page you can find the example usage for javafx.scene.control ListView setCellFactory.

Prototype

public final void setCellFactory(Callback<ListView<T>, ListCell<T>> value) 

Source Link

Document

Sets a new cell factory to use in the ListView.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    VBox box = new VBox();
    Scene scene = new Scene(box, 200, 200);
    stage.setScene(scene);//from  w ww.  j  a va2 s .  c om
    stage.setTitle("ListViewSample");
    box.getChildren().addAll(list, label);
    VBox.setVgrow(list, Priority.ALWAYS);

    label.setLayoutX(10);
    label.setLayoutY(115);
    label.setFont(Font.font("Verdana", 20));

    list.setItems(data);

    list.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override
        public ListCell<String> call(ListView<String> list) {
            return new ColorRectCell();
        }
    });

    list.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
        public void changed(ObservableValue<? extends String> ov, String old_val, String new_val) {
            label.setText(new_val);
            label.setTextFill(Color.web(new_val));
        }
    });
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {

    ObservableList<String> data = FXCollections.observableArrayList();

    ListView<String> listView = new ListView<String>(data);
    listView.setPrefSize(200, 250);//from   w ww.  ja  v a 2s .  c  om
    listView.setEditable(true);

    data.addAll("A", "B", "C", "D", "E");

    listView.setItems(data);
    listView.setCellFactory((ListView<String> l) -> new ColorRectCell());
    StackPane root = new StackPane();
    root.getChildren().add(listView);
    primaryStage.setScene(new Scene(root, 200, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    ObservableList<String> names = FXCollections.observableArrayList();
    ObservableList<String> data = FXCollections.observableArrayList();

    ListView<String> listView = new ListView<String>(data);
    listView.setPrefSize(200, 250);//from  ww  w  .  ja v a2  s .  com
    listView.setEditable(true);

    names.addAll("A", "B", "C", "D", "E");

    data.add("Double Click to Select Value");

    listView.setItems(data);
    listView.setCellFactory(ComboBoxListCell.forListView(names));

    StackPane root = new StackPane();
    root.getChildren().add(listView);
    primaryStage.setScene(new Scene(root, 200, 250));
    primaryStage.show();
}

From source file:Person.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 500, 250, Color.WHITE);
    // create a grid pane
    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);// w  ww  . j  a  va 2s. c om
    gridpane.setVgap(10);

    ObservableList<Person> leaders = FXCollections.observableArrayList();
    leaders.add(new Person("A", "B", "C"));
    leaders.add(new Person("D", "E", "F"));
    final ListView<Person> leaderListView = new ListView<Person>(leaders);
    leaderListView.setPrefWidth(150);
    leaderListView.setPrefHeight(150);

    // 
    leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() {

        public ListCell<Person> call(ListView<Person> param) {
            final Label leadLbl = new Label();
            final Tooltip tooltip = new Tooltip();
            final ListCell<Person> cell = new ListCell<Person>() {
                @Override
                public void updateItem(Person item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        leadLbl.setText(item.getAliasName());
                        setText(item.getFirstName() + " " + item.getLastName());
                        tooltip.setText(item.getAliasName());
                        setTooltip(tooltip);
                    }
                }
            }; // ListCell
            return cell;
        }
    }); // setCellFactory

    gridpane.add(leaderListView, 0, 1);

    leaderListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Person>() {
        public void changed(ObservableValue<? extends Person> observable, Person oldValue, Person newValue) {
            System.out.println("selection changed");
        }
    });

    root.getChildren().add(gridpane);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

private void initializeListView(ListView<Student> listView) {
    listView.setPrefSize(250, 290);// w w  w . ja  v  a  2s. com
    listView.setEditable(false);
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    listView.setCellFactory(new StringListCellFactory());
}

From source file:Main.java

private ListView<Person> createLeaderListView(ObservableList<Person> leaders) {
    final ListView<Person> leaderListView = new ListView<>(leaders);
    leaderListView.setPrefWidth(150);//from  w w w .  ja  va 2s . com
    leaderListView.setMaxWidth(Double.MAX_VALUE);
    leaderListView.setPrefHeight(150);

    leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() {
        @Override
        public ListCell<Person> call(ListView<Person> param) {
            Tooltip tooltip = new Tooltip();

            ListCell<Person> cell = new ListCell<Person>() {
                @Override
                public void updateItem(Person item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        // leadLbl.setText(item.getAliasName());
                        setText(item.getFirstName() + " " + item.getLastName());
                        tooltip.setText(item.getAliasName());
                        setTooltip(tooltip);
                    }
                }
            };
            return cell;
        }
    });

    return leaderListView;
}

From source file:cz.lbenda.gui.tableView.FilterMenuItem.java

private FilterMenuItem(VBox panel, FilterableTableView filterableTableView,
        FilterableTableColumn filterableTableColumn) {
    super(null, panel);
    this.filterableTableView = filterableTableView;
    okCancelBar.setAlignment(Pos.BOTTOM_RIGHT);
    this.tableColumn = filterableTableColumn;
    this.getStyleClass().add("listview-menu-item");

    SortedList<Item> sortedList = new SortedList<>(filteredList, Item::compareTo);
    ListView<Item> listView = new ListView<>();
    listView.setItems(sortedList);/*from   w  w  w .j a  v  a2s.  c  om*/
    listView.setCellFactory(CheckBoxListCell.forListView(Item::onProperty));

    TextField textField = new TextField();
    textField.textProperty().addListener((observable, oldValue, newValue) -> {
        filteredList.setPredicate(item -> StringUtils.isEmpty(newValue) || !StringUtils.isEmpty(item.getName())
                && item.getName().toLowerCase().contains(newValue.toLowerCase()));
    });

    prepareBars();
    prepareQuickFilter();
    prepareOkCancelBar();
    panel.getChildren().add(buttonBar);
    panel.getChildren().add(textField);
    panel.getChildren().add(listView);
    panel.getChildren().add(quickFilter);
    panel.getChildren().add(okCancelBar);

    //noinspection unchecked
    filterableTableView.sortProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue == null || (newValue != comparatorAsc && newValue != comparatorDsc)) {
            filterableTableColumn.removeRightIndicator(sortIndicator);
            sortToggleGroup.selectToggle(null);
        } else {
            filterableTableColumn.removeRightIndicator(sortIndicator);
            filterableTableColumn.addRightIndicator(sortIndicator);
            if (newValue == comparatorAsc) {
                sortIndicator.setImage(IconFactory.getInstance().image(this, ICON_SORT_ASC,
                        IconFactory.IconLocation.INDICATOR));
            } else {
                sortIndicator.setImage(IconFactory.getInstance().image(this, ICON_SORT_DSC,
                        IconFactory.IconLocation.INDICATOR));
            }
        }
    });
}

From source file:cz.lbenda.rcp.DialogHelper.java

/** Show unsaved object if aren't saved. if user want cancel the closing then return false, elserwhere return true
 * @param savableRegistry register which hold unsaved data
 * @return true if window/object can be closed */
public boolean showUnsavedObjectDialog(SavableRegistry savableRegistry) {
    Set<Savable> savables = savableRegistry.dirtySavables();
    if (savables.size() == 0) {
        return true;
    }//from ww w. ja va  2s  . c  o  m
    Dialog<?> dialog = new Dialog<>();
    dialog.setResizable(false);
    dialog.setTitle(msgNotSavedObjectsTitle);
    dialog.setHeaderText(msgNotSavedObjectsHeader);

    BorderPane pane = new BorderPane();
    pane.setPrefHeight(400);
    pane.setPrefWidth(300);
    ListView<DialogHelper.Item> listView = new ListView<>();
    listView.getItems()
            .addAll(savables.stream().map(savable -> new Item(savable, true)).collect(Collectors.toList()));
    listView.setCellFactory(CheckBoxListCell.forListView(DialogHelper.Item::onProperty));
    pane.setCenter(listView);

    dialog.getDialogPane().setContent(pane);

    ButtonType btCancel = new ButtonType(button_cancel, ButtonBar.ButtonData.CANCEL_CLOSE);
    ButtonType btSaveClose = new ButtonType(button_saveAndClose, ButtonBar.ButtonData.OK_DONE);
    ButtonType btClose = new ButtonType(button_closeWithoutSave);

    dialog.getDialogPane().getButtonTypes().addAll(btClose, btSaveClose, btCancel);

    Optional<?> result = dialog.showAndWait();
    if (result.isPresent()) {
        if (btCancel == result.get()) {
            return false;
        }
        if (btSaveClose == result.get()) {
            listView.getItems().stream().filter(Item::isOn).forEach(item -> item.getSavable().save());
        }
    } else {
        return false;
    }
    return true;
}

From source file:com.chart.SwingChart.java

/**
 * Series edition//ww  w .  j a va2s .c  om
 * @param series Series to edit
 */
void editSeries(final Series series) {
    String[] style = series.getStyle().split(";");
    String strColor = "black";
    final TextField editWidth = new TextField();

    String tempS = "null";
    for (String e : style) {
        if (e.contains("color: ")) {
            strColor = e.replace("color: ", "");
        } else if (e.contains("width: ")) {
            editWidth.setText(e.replace("width: ", ""));
        } else if (e.contains("shape: ")) {
            tempS = e.replace("shape: ", "");
        }
    }
    final String symbol = tempS;

    final List<SeriesShape> symbolList = new ArrayList<>();
    final ObservableList<SeriesShape> symbolListModel;
    final ListView<SeriesShape> comboSymbol = new ListView();
    symbolList.add(new SeriesShape("null", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("rectangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("circle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("triangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("crux", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("diamond", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty rectangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty circle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty triangle", javafx.scene.paint.Color.web(strColor)));
    symbolList.add(new SeriesShape("empty diamond", javafx.scene.paint.Color.web(strColor)));

    symbolListModel = FXCollections.observableList(symbolList);
    comboSymbol.setItems(symbolListModel);
    comboSymbol.setCellFactory(new Callback<ListView<SeriesShape>, ListCell<SeriesShape>>() {
        @Override
        public ListCell<SeriesShape> call(ListView<SeriesShape> p) {
            ListCell<SeriesShape> cell = new ListCell<SeriesShape>() {
                @Override
                protected void updateItem(SeriesShape t, boolean bln) {
                    super.updateItem(t, bln);
                    if (t != null) {
                        setText("");
                        setGraphic(t.getShapeGraphic());
                    }
                }
            };

            return cell;
        }
    });
    for (SeriesShape smb : symbolListModel) {
        if (smb.getName().equals(symbol)) {
            comboSymbol.getSelectionModel().select(smb);
        }
    }

    final ColorPicker colorPicker = new ColorPicker(javafx.scene.paint.Color.web(strColor));

    colorPicker.setOnAction((ActionEvent t) -> {
        String sc = colorPicker.getValue().toString();
        symbolListModel.clear();
        symbolListModel.add(new SeriesShape("null", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("rectangle", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("circle", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("triangle", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("crux", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("diamond", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("empty rectangle", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("empty circle", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("empty triangle", javafx.scene.paint.Color.web(sc)));
        symbolListModel.add(new SeriesShape("empty diamond", javafx.scene.paint.Color.web(sc)));

        comboSymbol.setItems(symbolListModel);
        for (SeriesShape smb : symbolListModel) {
            if (smb.getName().equals(symbol)) {
                comboSymbol.getSelectionModel().select(smb);
            }
        }
    });

    GridPane grid = new GridPane();

    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));

    grid.add(new Label("Series"), 0, 0);
    grid.add(new Label(series.getKey().toString()), 1, 0);
    grid.add(new Label("Color"), 0, 1);
    grid.add(colorPicker, 1, 1);
    grid.add(new Label("Width"), 0, 2);
    grid.add(editWidth, 1, 2);
    grid.add(new Label("Shape"), 0, 3);
    grid.add(comboSymbol, 1, 3);

    new PseudoModalDialog(skeleton, grid, true) {
        @Override
        public boolean validation() {
            String strColor = colorPicker.getValue().toString();
            String strWidth = editWidth.getText();
            double dWidth = Double.valueOf(strWidth);
            String strSimbolo = "null";
            SeriesShape simb = new SeriesShape(comboSymbol.getSelectionModel().getSelectedItem().toString(),
                    javafx.scene.paint.Color.web(strColor));

            XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer(series.getAxisIndex());

            renderer.setSeriesPaint(series.getSeriesIndex(), scene2awtColor(colorPicker.getValue()));

            try {
                if (Double.valueOf(strWidth) > 0) {
                    ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(series.getSeriesIndex(), true);
                    renderer.setSeriesStroke(series.getSeriesIndex(),
                            new BasicStroke(Integer.valueOf(strWidth)));
                } else {
                    ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(series.getSeriesIndex(), false);
                }
            } catch (NumberFormatException ex) {

            }

            if (simb.getName().contains("null")) {
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(series.getSeriesIndex(), false);
                renderer.setSeriesShape(series.getSeriesIndex(), null);
            } else {
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(series.getSeriesIndex(), true);
                renderer.setSeriesShape(series.getSeriesIndex(), simb.getShapeAWT());
                if (simb.getName().contains("empty")) {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(series.getSeriesIndex(), false);
                } else {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(series.getSeriesIndex(), true);
                }

            }

            series.setStyle(
                    "color: " + strColor + ";width: " + editWidth.getText() + ";shape: " + strSimbolo + ";");

            for (Node le : legendFrame.getChildren()) {
                if (le instanceof LegendAxis) {
                    for (Node nn : ((LegendAxis) le).getChildren()) {
                        if (nn instanceof Label) {
                            if (((Label) nn).getText().equals(series.getKey().toString())) {
                                ((Label) nn).setGraphic(simb.getShapeGraphic());
                            }
                        }
                    }
                }
            }
            return true;
        }
    }.show();

}

From source file:qupath.lib.gui.tma.TMASummaryViewer.java

private Pane createSidePane() {
    BorderPane pane = new BorderPane();

    TabPane tabPane = new TabPane();

    kmDisplay = new KaplanMeierDisplay(null, null, null, null);
    BorderPane paneKaplanMeier = new BorderPane();
    paneKaplanMeier.setCenter(kmDisplay.getView());
    paneKaplanMeier.setPadding(new Insets(10, 10, 10, 10));
    //      comboMainMeasurement.prefWidthProperty().bind(paneKaplanMeier.widthProperty());
    comboMainMeasurement.setMaxWidth(Double.MAX_VALUE);
    comboMainMeasurement.setTooltip(new Tooltip("Measurement thresholded to create survival curves etc."));

    GridPane kmTop = new GridPane();
    kmTop.add(new Label("Score"), 0, 0);
    kmTop.add(comboMainMeasurement, 1, 0);
    kmTop.add(new Label("Survival type"), 0, 1);
    kmTop.add(comboSurvival, 1, 1);/*  w w w.j  ava 2s. co  m*/
    comboSurvival.setTooltip(new Tooltip("Specify overall or recurrence-free survival (if applicable)"));
    comboSurvival.setMaxWidth(Double.MAX_VALUE);
    GridPane.setHgrow(comboMainMeasurement, Priority.ALWAYS);
    GridPane.setHgrow(comboSurvival, Priority.ALWAYS);
    kmTop.setHgap(5);
    paneKaplanMeier.setTop(kmTop);
    //      kmDisplay.setOrientation(Orientation.VERTICAL);

    histogramDisplay = new HistogramDisplay(model, false);

    comboMainMeasurement.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> {
        histogramDisplay.refreshCombo();
        histogramDisplay.showHistogram(n);
        updateSurvivalCurves();
    });
    comboMeasurementMethod.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> {
        histogramDisplay.refreshHistogram();
        scatterPane.updateChart();
        updateSurvivalCurves();
    });
    comboSurvival.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> {
        updateSurvivalCurves();
    });

    // Create a Tab for showing images
    BorderPane paneImages = new BorderPane();
    CheckBox cbShowOverlay = new CheckBox("Show overlay");
    imageAvailability.addListener((c, v, n) -> {
        if (n == ImageAvailability.OVERLAY_ONLY)
            cbShowOverlay.setSelected(true);
        else if (n == ImageAvailability.IMAGE_ONLY)
            cbShowOverlay.setSelected(false);
        cbShowOverlay.setDisable(n != ImageAvailability.BOTH);
    });
    ListView<TMAEntry> listImages = new ListView<>();
    listImages.setCellFactory(v -> new ImageListCell(cbShowOverlay.selectedProperty(), imageCache));
    listImages.widthProperty().addListener((v, o, n) -> listImages.refresh());
    listImages.setStyle("-fx-control-inner-background-alt: -fx-control-inner-background ;");
    table.getSelectionModel().getSelectedItems().addListener((Change<? extends TreeItem<TMAEntry>> e) -> {
        List<TMAEntry> entries = new ArrayList<>();
        for (TreeItem<TMAEntry> item : e.getList()) {
            if (item.getChildren().isEmpty()) {
                if (item.getValue().hasImage() || item.getValue().hasOverlay())
                    entries.add(item.getValue());
            } else {
                for (TreeItem<TMAEntry> item2 : item.getChildren()) {
                    if (item2.getValue().hasImage() || item2.getValue().hasOverlay())
                        entries.add(item2.getValue());
                }
            }
            listImages.getItems().setAll(entries);
        }
    });
    cbShowOverlay.setAlignment(Pos.CENTER);
    cbShowOverlay.setMaxWidth(Double.MAX_VALUE);
    cbShowOverlay.setPadding(new Insets(5, 5, 5, 5));
    cbShowOverlay.selectedProperty().addListener((v, o, n) -> listImages.refresh());
    paneImages.setCenter(listImages);
    paneImages.setTop(cbShowOverlay);

    // Determine visibility based upon whether there are any images to show
    //      Tab tabImages = new Tab("Images", paneImages);

    ScrollPane scrollPane = new ScrollPane(paneKaplanMeier);
    scrollPane.setFitToWidth(true);
    scrollPane.setFitToHeight(true);
    scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
    scrollPane.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
    Tab tabSurvival = new Tab("Survival", scrollPane);
    tabPane.getTabs().addAll(new Tab("Table", getCustomizeTablePane()),
            //            tabImages,
            new Tab("Histogram", histogramDisplay.getPane()), new Tab("Scatterplot", scatterPane.getPane()),
            tabSurvival);
    tabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);

    //      if (imageAvailability.get() != ImageAvailability.NONE)
    //         tabPane.getTabs().add(1, tabImages);
    //      
    //      imageAvailability.addListener((c, v, n) -> {
    //         if (n == ImageAvailability.NONE)
    //            tabPane.getTabs().remove(tabImages);
    //         else if (!tabPane.getTabs().contains(tabImages))
    //            tabPane.getTabs().add(1, tabImages);
    //      });

    //      tabSurvival.visibleProperty().bind(
    //            Bindings.createBooleanBinding(() -> !survivalColumns.isEmpty(), survivalColumns)
    //            );

    pane.setCenter(tabPane);

    pane.setMinWidth(350);

    return pane;
}