Example usage for javafx.scene.layout GridPane setStyle

List of usage examples for javafx.scene.layout GridPane setStyle

Introduction

In this page you can find the example usage for javafx.scene.layout GridPane setStyle.

Prototype

public final void setStyle(String value) 

Source Link

Document

A string representation of the CSS style associated with this specific Node .

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    TextField fNameFld = new TextField();
    Label fNameLbl = new Label("First Name:");

    TextField lNameFld = new TextField();
    Label lNameLbl = new Label("Last Name:");

    GridPane root = new GridPane();
    root.addRow(0, fNameLbl, fNameFld);//from w w  w  .j  a v  a2s .com
    root.addRow(1, lNameLbl, lNameFld);

    // Set a CSS for the GridPane
    root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;"
            + "-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;");

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}

From source file:gov.va.isaac.gui.refexViews.refexEdit.AddSememePopup.java

private void buildDataFields(boolean assemblageValid, DynamicSememeDataBI[] currentValues) {
    if (assemblageValid) {
        for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) {
            allValid_.removeBinding(ssp);
        }/*from  w w w.j  av  a2s.  c  o  m*/
        currentDataFieldWarnings_.clear();
        for (SememeGUIDataTypeNodeDetails nd : currentDataFields_) {
            nd.cleanupListener();
        }
        currentDataFields_.clear();

        GridPane gp = new GridPane();
        gp.setHgap(10.0);
        gp.setVgap(10.0);
        gp.setStyle("-fx-padding: 5;");
        int row = 0;
        boolean extraInfoColumnIsRequired = false;
        for (DynamicSememeColumnInfo ci : assemblageInfo_.getColumnInfo()) {
            SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("")
                    : null);
            SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null
                    && ci.getValidator() == null) ? null : new SimpleStringProperty());
            ComboBox<DynamicSememeDataType> polymorphicType = null;

            Label l = new Label(ci.getColumnName());
            l.getStyleClass().add("boldLabel");
            l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l));
            Tooltip.install(l, new Tooltip(ci.getColumnDescription()));
            int col = 0;
            gp.add(l, col++, row);

            if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) {
                polymorphicType = new ComboBox<>();
                polymorphicType.setEditable(false);
                polymorphicType.setConverter(new StringConverter<DynamicSememeDataType>() {

                    @Override
                    public String toString(DynamicSememeDataType object) {
                        return object.getDisplayName();
                    }

                    @Override
                    public DynamicSememeDataType fromString(String string) {
                        throw new RuntimeException("unecessary");
                    }
                });
                for (DynamicSememeDataType type : DynamicSememeDataType.values()) {
                    if (type == DynamicSememeDataType.POLYMORPHIC || type == DynamicSememeDataType.UNKNOWN) {
                        continue;
                    } else {
                        polymorphicType.getItems().add(type);
                    }
                }
                polymorphicType.getSelectionModel()
                        .select((currentValues == null ? DynamicSememeDataType.STRING
                                : (currentValues[row] == null ? DynamicSememeDataType.STRING
                                        : currentValues[row].getDynamicSememeDataType())));
            }

            SememeGUIDataTypeNodeDetails nd = SememeGUIDataTypeFXNodeBuilder.buildNodeForType(
                    ci.getColumnDataType(), ci.getDefaultColumnValue(),
                    (currentValues == null ? null : currentValues[row]), valueIsRequired, defaultValueTooltip,
                    (polymorphicType == null ? null
                            : polymorphicType.getSelectionModel().selectedItemProperty()),
                    allValid_, ci.getValidator(), ci.getValidatorData());

            currentDataFieldWarnings_.addAll(nd.getBoundToAllValid());
            if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) {
                nd.addUpdateParentListListener(currentDataFieldWarnings_);
            }

            currentDataFields_.add(nd);

            gp.add(nd.getNodeForDisplay(), col++, row);

            Label colType = new Label(ci.getColumnDataType().getDisplayName());
            colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType));
            gp.add((polymorphicType == null ? colType : polymorphicType), col++, row);

            if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                extraInfoColumnIsRequired = true;

                StackPane stackPane = new StackPane();
                stackPane.setMaxWidth(Double.MAX_VALUE);

                if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                    ImageView information = Images.INFORMATION.createImageView();
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(defaultValueTooltip);
                    Tooltip.install(information, tooltip);
                    tooltip.setAutoHide(true);
                    information.setOnMouseClicked(
                            event -> tooltip.show(information, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(information);
                }

                if (ci.isColumnRequired()) {
                    ImageView exclamation = Images.EXCLAMATION.createImageView();

                    final BooleanProperty showExclamation = new SimpleBooleanProperty(
                            StringUtils.isNotBlank(valueIsRequired.get()));
                    valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue,
                            newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue)));

                    exclamation.visibleProperty().bind(showExclamation);
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(valueIsRequired);
                    Tooltip.install(exclamation, tooltip);
                    tooltip.setAutoHide(true);

                    exclamation.setOnMouseClicked(
                            event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(exclamation);
                }

                gp.add(stackPane, col++, row);
            }
            row++;
        }

        ColumnConstraints cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.ALWAYS);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        if (extraInfoColumnIsRequired) {
            cc = new ColumnConstraints();
            cc.setHgrow(Priority.NEVER);
            gp.getColumnConstraints().add(cc);
        }

        if (row == 0) {
            sp_.setContent(new Label("This assemblage does not allow data fields"));
        } else {
            sp_.setContent(gp);
        }
        allValid_.invalidate();
    } else {
        sp_.setContent(null);
    }
}

From source file:gov.va.isaac.gui.refexViews.refexEdit.AddRefexPopup.java

private void buildDataFields(boolean assemblageValid, RefexDynamicDataBI[] currentValues) {
    if (assemblageValid) {
        for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) {
            allValid_.removeBinding(ssp);
        }/*w w  w.  java  2  s  . c o m*/
        currentDataFieldWarnings_.clear();
        for (RefexDataTypeNodeDetails nd : currentDataFields_) {
            nd.cleanupListener();
        }
        currentDataFields_.clear();

        GridPane gp = new GridPane();
        gp.setHgap(10.0);
        gp.setVgap(10.0);
        gp.setStyle("-fx-padding: 5;");
        int row = 0;
        boolean extraInfoColumnIsRequired = false;
        for (RefexDynamicColumnInfo ci : assemblageInfo_.getColumnInfo()) {
            SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("")
                    : null);
            SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null
                    && ci.getValidator() == null) ? null : new SimpleStringProperty());
            ComboBox<RefexDynamicDataType> polymorphicType = null;

            Label l = new Label(ci.getColumnName());
            l.getStyleClass().add("boldLabel");
            l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l));
            Tooltip.install(l, new Tooltip(ci.getColumnDescription()));
            int col = 0;
            gp.add(l, col++, row);

            if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) {
                polymorphicType = new ComboBox<>();
                polymorphicType.setEditable(false);
                polymorphicType.setConverter(new StringConverter<RefexDynamicDataType>() {

                    @Override
                    public String toString(RefexDynamicDataType object) {
                        return object.getDisplayName();
                    }

                    @Override
                    public RefexDynamicDataType fromString(String string) {
                        throw new RuntimeException("unecessary");
                    }
                });
                for (RefexDynamicDataType type : RefexDynamicDataType.values()) {
                    if (type == RefexDynamicDataType.POLYMORPHIC || type == RefexDynamicDataType.UNKNOWN) {
                        continue;
                    } else {
                        polymorphicType.getItems().add(type);
                    }
                }
                polymorphicType.getSelectionModel()
                        .select((currentValues == null ? RefexDynamicDataType.STRING
                                : (currentValues[row] == null ? RefexDynamicDataType.STRING
                                        : currentValues[row].getRefexDataType())));
            }

            RefexDataTypeNodeDetails nd = RefexDataTypeFXNodeBuilder.buildNodeForType(ci.getColumnDataType(),
                    ci.getDefaultColumnValue(), (currentValues == null ? null : currentValues[row]),
                    valueIsRequired, defaultValueTooltip,
                    (polymorphicType == null ? null
                            : polymorphicType.getSelectionModel().selectedItemProperty()),
                    allValid_, new SimpleObjectProperty<>(ci.getValidator()),
                    new SimpleObjectProperty<>(ci.getValidatorData()));

            currentDataFieldWarnings_.addAll(nd.getBoundToAllValid());
            if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) {
                nd.addUpdateParentListListener(currentDataFieldWarnings_);
            }

            currentDataFields_.add(nd);

            gp.add(nd.getNodeForDisplay(), col++, row);

            Label colType = new Label(ci.getColumnDataType().getDisplayName());
            colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType));
            gp.add((polymorphicType == null ? colType : polymorphicType), col++, row);

            if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                extraInfoColumnIsRequired = true;

                StackPane stackPane = new StackPane();
                stackPane.setMaxWidth(Double.MAX_VALUE);

                if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) {
                    ImageView information = Images.INFORMATION.createImageView();
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(defaultValueTooltip);
                    Tooltip.install(information, tooltip);
                    tooltip.setAutoHide(true);
                    information.setOnMouseClicked(
                            event -> tooltip.show(information, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(information);
                }

                if (ci.isColumnRequired()) {
                    ImageView exclamation = Images.EXCLAMATION.createImageView();

                    final BooleanProperty showExclamation = new SimpleBooleanProperty(
                            StringUtils.isNotBlank(valueIsRequired.get()));
                    valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue,
                            newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue)));

                    exclamation.visibleProperty().bind(showExclamation);
                    Tooltip tooltip = new Tooltip();
                    tooltip.textProperty().bind(valueIsRequired);
                    Tooltip.install(exclamation, tooltip);
                    tooltip.setAutoHide(true);

                    exclamation.setOnMouseClicked(
                            event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY()));
                    stackPane.getChildren().add(exclamation);
                }

                gp.add(stackPane, col++, row);
            }
            row++;
        }

        ColumnConstraints cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.ALWAYS);
        gp.getColumnConstraints().add(cc);

        cc = new ColumnConstraints();
        cc.setHgrow(Priority.NEVER);
        gp.getColumnConstraints().add(cc);

        if (extraInfoColumnIsRequired) {
            cc = new ColumnConstraints();
            cc.setHgrow(Priority.NEVER);
            gp.getColumnConstraints().add(cc);
        }

        if (row == 0) {
            sp_.setContent(new Label("This assemblage does not allow data fields"));
        } else {
            sp_.setContent(gp);
        }
        allValid_.invalidate();
    } else {
        sp_.setContent(null);
    }
}