Example usage for javafx.scene.layout VBox setMaxSize

List of usage examples for javafx.scene.layout VBox setMaxSize

Introduction

In this page you can find the example usage for javafx.scene.layout VBox setMaxSize.

Prototype

public void setMaxSize(double maxWidth, double maxHeight) 

Source Link

Document

Convenience method for overriding the region's computed maximum width and height.

Usage

From source file:org.jacp.demo.components.ContactAddDialog.java

private void createAddContactDialog() {
    final VBox box = new VBox();
    box.getStyleClass().add("jacp-option-pane");
    box.setMaxSize(300, Region.USE_PREF_SIZE);
    // the title/*from   w w w.  j a va  2 s .  co  m*/
    final Label title = new Label("Add new category");
    title.setId(GlobalConstants.CSSConstants.ID_JACP_CUSTOM_TITLE);
    VBox.setMargin(title, new Insets(2, 2, 10, 2));

    final HBox hboxInput = new HBox();
    final Label nameLabel = new Label("category name:");
    HBox.setMargin(nameLabel, new Insets(2));
    final TextField nameInput = new TextField();
    HBox.setMargin(nameInput, new Insets(0, 0, 0, 5));
    HBox.setHgrow(nameInput, Priority.ALWAYS);
    hboxInput.getChildren().addAll(nameLabel, nameInput);

    final HBox hboxButtons = new HBox();
    hboxButtons.setAlignment(Pos.CENTER_RIGHT);
    final Button ok = new Button("OK");
    HBox.setMargin(ok, new Insets(6, 5, 4, 2));
    final Button cancel = new Button("Cancel");
    HBox.setMargin(cancel, new Insets(6, 2, 4, 5));
    cancel.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(final ActionEvent arg0) {
            JACPModalDialog.getInstance().hideModalDialog();
        }
    });

    ok.setDefaultButton(true);
    ok.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(final ActionEvent actionEvent) {
            final String catName = nameInput.getText();
            if (catName != null && StringUtils.hasText(catName)) {
                // contacts
                final Contact contact = new Contact();
                contact.setFirstName(catName);
                parent.getContext().send(contact);
                JACPModalDialog.getInstance().hideModalDialog();
            }
        }
    });

    hboxButtons.getChildren().addAll(ok, cancel);
    box.getChildren().addAll(title, hboxInput, hboxButtons);
    JACPModalDialog.getInstance().showModalDialog(box);
}