Search in sources :

Example 1 with NodeConverter

use of com.jfoenix.converters.base.NodeConverter in project JFoenix by jfoenixadmin.

the class JFXComboBox method defaultNodeConverter.

private static <T> NodeConverter<T> defaultNodeConverter() {
    return new NodeConverter<T>() {

        @Override
        public Node toNode(T object) {
            if (object == null)
                return null;
            StackPane selectedValueContainer = new StackPane();
            selectedValueContainer.getStyleClass().add("combo-box-selected-value-container");
            selectedValueContainer.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, null, null)));
            Label selectedValueLabel;
            if (object instanceof Label)
                selectedValueLabel = new Label(((Label) object).getText());
            else
                selectedValueLabel = new Label(object.toString());
            selectedValueLabel.setTextFill(Color.BLACK);
            selectedValueContainer.getChildren().add(selectedValueLabel);
            StackPane.setAlignment(selectedValueLabel, Pos.CENTER_LEFT);
            StackPane.setMargin(selectedValueLabel, new Insets(0, 0, 0, 5));
            return selectedValueContainer;
        }

        @SuppressWarnings("unchecked")
        @Override
        public T fromNode(Node node) {
            return (T) node;
        }

        @Override
        public String toString(T object) {
            if (object == null)
                return null;
            if (object instanceof Label)
                return ((Label) object).getText();
            return object.toString();
        }
    };
}
Also used : Insets(javafx.geometry.Insets) Background(javafx.scene.layout.Background) NodeConverter(com.jfoenix.converters.base.NodeConverter) BackgroundFill(javafx.scene.layout.BackgroundFill) Node(javafx.scene.Node) StackPane(javafx.scene.layout.StackPane)

Aggregations

NodeConverter (com.jfoenix.converters.base.NodeConverter)1 Insets (javafx.geometry.Insets)1 Node (javafx.scene.Node)1 Background (javafx.scene.layout.Background)1 BackgroundFill (javafx.scene.layout.BackgroundFill)1 StackPane (javafx.scene.layout.StackPane)1