Java Code Examples for javafx.scene.layout.VBox#setPrefWidth()

The following examples show how to use javafx.scene.layout.VBox#setPrefWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MouseLocationReporter.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override public void start(final Stage stage) {
  final Label reporter = new Label(OUTSIDE_TEXT);
  Label monitored = createMonitoredLabel(reporter);

  VBox layout = new VBox(10);
  layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10px;");
  layout.getChildren().setAll(
    monitored,
    reporter
  );
  layout.setPrefWidth(500);

  stage.setScene(
    new Scene(layout)
  );

  stage.show();
}
 
Example 2
Source File: SearchBoxSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public SearchBoxSample() {
    String searchBoxCss = SearchBoxSample.class.getResource("SearchBox.css").toExternalForm();
    VBox vbox = VBoxBuilder.create().build();
    vbox.getStylesheets().add(searchBoxCss);
    vbox.setPrefWidth(200);
    vbox.setMaxWidth(Control.USE_PREF_SIZE);
    vbox.getChildren().add(new SearchBox());
    getChildren().add(vbox);
}
 
Example 3
Source File: SearchBoxSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public SearchBoxSample() {
    String searchBoxCss = SearchBoxSample.class.getResource("SearchBox.css").toExternalForm();
    VBox vbox = VBoxBuilder.create().build();
    vbox.getStylesheets().add(searchBoxCss);
    vbox.setPrefWidth(200);
    vbox.setMaxWidth(Control.USE_PREF_SIZE);
    vbox.getChildren().add(new SearchBox());
    getChildren().add(vbox);
}
 
Example 4
Source File: AboutLogFXView.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
VBox createNode() {
    VBox contents = new VBox( 25 );
    contents.setPrefSize( 500, 300 );
    contents.setAlignment( Pos.CENTER );
    contents.getStylesheets().add( "css/about.css" );

    HBox textBox = new HBox( 0 );
    textBox.setPrefWidth( 500 );
    textBox.setAlignment( Pos.CENTER );
    Text logText = new Text( "Log" );
    logText.setId( "logfx-text-log" );
    Text fxText = new Text( "FX" );
    fxText.setId( "logfx-text-fx" );
    textBox.getChildren().addAll( logText, fxText );

    VBox smallText = new VBox( 10 );
    smallText.setPrefWidth( 500 );
    smallText.setAlignment( Pos.CENTER );
    Text version = new Text( "Version " + Constants.LOGFX_VERSION );
    Text byRenato = new Text( "Copyright Renato Athaydes, 2017. All rights reserved." );
    Text license = new Text( "Licensed under the GPLv3 License." );
    Hyperlink link = new Hyperlink( "https://github.com/renatoathaydes/LogFX" );
    link.setOnAction( ( event ) -> hostServices.showDocument( link.getText() ) );
    smallText.getChildren().addAll( version, byRenato, link, license );

    contents.getChildren().addAll( textBox, smallText );

    return contents;
}
 
Example 5
Source File: RepositoryPickerDialog.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createSuggestedRepositoriesList() {
    suggestedRepositoryList = new VBox();
    suggestedRepositoryList.setPadding(DEFAULT_PADDING);
    suggestedRepositoryList.setId(IdGenerator.getRepositoryPickerSuggestedRepoListId());
    suggestedRepositoryList.setStyle("-fx-background-color: white; -fx-border-color:black;");
    suggestedRepositoryList.setPrefHeight(DEFAULT_SUGGESTED_REPO_LIST_HEIGHT);
    suggestedRepositoryList.setPrefWidth(DEFAULT_SUGGESTED_REPO_LIST_WIDTH);
}
 
Example 6
Source File: VertexGraphLabelsEditorFactory.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
protected Node createEditorControls() {
    // get all vertex attributes currently in the graph
    final ReadableGraph rg = GraphManager.getDefault().getActiveGraph().getReadableGraph();
    try {
        for (int i = 0; i < rg.getAttributeCount(GraphElementType.VERTEX); i++) {
            attributeNames.add(rg.getAttributeName(rg.getAttribute(GraphElementType.VERTEX, i)));
        }
    } finally {
        rg.release();
    }
    attributeNames.sort(String::compareTo);

    HBox labelTitles = new HBox();
    final Label attrLabel = new Label("Attribute");
    attrLabel.setAlignment(Pos.CENTER);
    attrLabel.setPrefWidth(150);
    final Label colorLabel = new Label("Colour");
    colorLabel.setPrefWidth(40);
    colorLabel.setAlignment(Pos.CENTER);
    final Label sizeLabel = new Label("Size");
    sizeLabel.setPrefWidth(50);
    sizeLabel.setAlignment(Pos.CENTER);
    final Label positionLabel = new Label("Position");
    positionLabel.setPrefWidth(115);
    positionLabel.setAlignment(Pos.CENTER);
    labelTitles.getChildren().addAll(attrLabel, colorLabel, sizeLabel, positionLabel);
    labelPaneContent.setPadding(new Insets(5));
    labelPaneContent.getChildren().addAll(labelTitles, labelEntries);

    final ScrollPane labelsScrollPane = new ScrollPane();
    labelsScrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    labelsScrollPane.setPrefHeight(200);
    labelsScrollPane.setPrefWidth(400);
    labelsScrollPane.setContent(labelPaneContent);

    addButton.setOnAction(e -> {
        new LabelEntry(labels, labelEntries, attributeNames.isEmpty() ? "" : attributeNames.get(0), ConstellationColor.LIGHT_BLUE, 1);
        addButton.setDisable(labels.size() == GraphLabels.MAX_LABELS);
        update();
    });
    final Label addButtonLabel = new Label("Add Label");
    final FlowPane addPane = new FlowPane();
    addPane.setHgap(10);
    addPane.setAlignment(Pos.CENTER_RIGHT);
    addPane.getChildren().addAll(addButtonLabel, addButton);

    final VBox controls = new VBox(10);
    controls.setPrefWidth(400);
    controls.getChildren().addAll(labelsScrollPane, addPane);

    return controls;
}
 
Example 7
Source File: TransactionGraphLabelsEditorFactory.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
protected Node createEditorControls() {
    // get all transaction attributes currently in the graph
    final ReadableGraph rg = GraphManager.getDefault().getActiveGraph().getReadableGraph();
    try {
        for (int i = 0; i < rg.getAttributeCount(GraphElementType.TRANSACTION); i++) {
            attributeNames.add(rg.getAttributeName(rg.getAttribute(GraphElementType.TRANSACTION, i)));
        }
    } finally {
        rg.release();
    }
    attributeNames.sort(String::compareTo);

    final HBox labelTitles = new HBox();
    final Label attrLabel = new Label("Attribute");
    attrLabel.setAlignment(Pos.CENTER);
    attrLabel.setPrefWidth(150);
    final Label colorLabel = new Label("Colour");
    colorLabel.setPrefWidth(40);
    colorLabel.setAlignment(Pos.CENTER);
    final Label sizeLabel = new Label("Size");
    sizeLabel.setPrefWidth(50);
    sizeLabel.setAlignment(Pos.CENTER);
    final Label positionLabel = new Label("Position");
    positionLabel.setPrefWidth(115);
    positionLabel.setAlignment(Pos.CENTER);
    labelTitles.getChildren().addAll(attrLabel, colorLabel, sizeLabel, positionLabel);
    labelPaneContent.setPadding(new Insets(5));
    labelPaneContent.getChildren().addAll(labelTitles, labelEntries);

    final ScrollPane labelsScrollPane = new ScrollPane();
    labelsScrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    labelsScrollPane.setPrefHeight(200);
    labelsScrollPane.setPrefWidth(400);
    labelsScrollPane.setContent(labelPaneContent);

    addButton.setOnAction(e -> {
        new LabelEntry(labels, labelEntries, attributeNames.isEmpty() ? "" : attributeNames.get(0), ConstellationColor.LIGHT_BLUE, 1);
        addButton.setDisable(labels.size() == GraphLabels.MAX_LABELS);
        update();
    });
    final Label addButtonLabel = new Label("Add Label");
    final FlowPane addPane = new FlowPane();
    addPane.setHgap(10);
    addPane.setAlignment(Pos.CENTER_RIGHT);
    addPane.getChildren().addAll(addButtonLabel, addButton);

    final VBox controls = new VBox(10);
    controls.setPrefWidth(400);
    controls.getChildren().addAll(labelsScrollPane, addPane);

    return controls;
}
 
Example 8
Source File: SearchBox.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public SearchBox() {
    setId("SearchBox");
    setMinHeight(24);
    setPrefSize(150, 24);
    setMaxHeight(24);
    textBox = new TextField();
    textBox.setPromptText("Search");
    clearButton = new Button();
    clearButton.setVisible(false);
    getChildren().addAll(textBox, clearButton);
    clearButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent actionEvent) {
            textBox.setText("");
            textBox.requestFocus();
        }
    });
    textBox.setOnKeyReleased(new EventHandler<KeyEvent>() {
        @Override public void handle(KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.DOWN) {
                ///System.out.println("SearchBox.handle DOWN");
                contextMenu.setFocused(true);
            }
        }
    });
    textBox.textProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            clearButton.setVisible(textBox.getText().length() != 0);
            if (textBox.getText().length() == 0) {
                if (contextMenu != null) contextMenu.hide();
                showError(null);
            } else {
                boolean haveResults = false;
                Map<DocumentType, List<SearchResult>> results = null;
                try {
                    if (indexSearcher == null) indexSearcher = new IndexSearcher();
                    results = indexSearcher.search(
                            textBox.getText() + (textBox.getText().matches("\\w+") ? "*" : "")
                    );
                    // check if we have any results
                    for (List<SearchResult> categoryResults: results.values()) {
                        if (categoryResults.size() > 0) {
                            haveResults = true;
                            break;
                        }
                    }
                } catch (ParseException e) {
                    showError(e.getMessage().substring("Cannot parse ".length()));
                }
                if (haveResults) {
                    showError(null);
                    populateMenu(results);
                    if (!contextMenu.isShowing()) contextMenu.show(SearchBox.this, Side.BOTTOM, 10,-5);
                } else {
                    if (searchErrorTooltip.getText() == null) showError("No matches");
                    contextMenu.hide();
                }
                contextMenu.setFocused(true);
            }
        }
    });
    // create info popup
    infoBox = new VBox();
    infoBox.setId("search-info-box");
    infoBox.setFillWidth(true);
    infoBox.setMinWidth(USE_PREF_SIZE);
    infoBox.setPrefWidth(350);
    infoName = new Label();
    infoName.setId("search-info-name");
    infoName.setMinHeight(USE_PREF_SIZE);
    infoName.setPrefHeight(28);
    infoDescription = new Label();
    infoDescription.setId("search-info-description");
    infoDescription.setWrapText(true);
    infoDescription.setPrefWidth(infoBox.getPrefWidth()-24);
    infoBox.getChildren().addAll(infoName,infoDescription);
    extraInfoPopup.getContent().add(infoBox);
    // hide info popup when context menu is hidden
    contextMenu.setOnHidden(new EventHandler<WindowEvent>() {
        @Override public void handle(WindowEvent windowEvent) {
            extraInfoPopup.hide();
        }
    });
}
 
Example 9
Source File: SearchBox.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public SearchBox() {
    setId("SearchBox");
    setMinHeight(24);
    setPrefSize(150, 24);
    setMaxHeight(24);
    textBox = new TextField();
    textBox.setPromptText("Search");
    clearButton = new Button();
    clearButton.setVisible(false);
    getChildren().addAll(textBox, clearButton);
    clearButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent actionEvent) {
            textBox.setText("");
            textBox.requestFocus();
        }
    });
    textBox.setOnKeyReleased(new EventHandler<KeyEvent>() {
        @Override public void handle(KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.DOWN) {
                ///System.out.println("SearchBox.handle DOWN");
                contextMenu.setFocused(true);
            }
        }
    });
    textBox.textProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            clearButton.setVisible(textBox.getText().length() != 0);
            if (textBox.getText().length() == 0) {
                if (contextMenu != null) contextMenu.hide();
                showError(null);
            } else {
                boolean haveResults = false;
                Map<DocumentType, List<SearchResult>> results = null;
                try {
                    if (indexSearcher == null) indexSearcher = new IndexSearcher();
                    results = indexSearcher.search(
                            textBox.getText() + (textBox.getText().matches("\\w+") ? "*" : "")
                    );
                    // check if we have any results
                    for (List<SearchResult> categoryResults: results.values()) {
                        if (categoryResults.size() > 0) {
                            haveResults = true;
                            break;
                        }
                    }
                } catch (ParseException e) {
                    showError(e.getMessage().substring("Cannot parse ".length()));
                }
                if (haveResults) {
                    showError(null);
                    populateMenu(results);
                    if (!contextMenu.isShowing()) contextMenu.show(SearchBox.this, Side.BOTTOM, 10,-5);
                } else {
                    if (searchErrorTooltip.getText() == null) showError("No matches");
                    contextMenu.hide();
                }
                contextMenu.setFocused(true);
            }
        }
    });
    // create info popup
    infoBox = new VBox();
    infoBox.setId("search-info-box");
    infoBox.setFillWidth(true);
    infoBox.setMinWidth(USE_PREF_SIZE);
    infoBox.setPrefWidth(350);
    infoName = new Label();
    infoName.setId("search-info-name");
    infoName.setMinHeight(USE_PREF_SIZE);
    infoName.setPrefHeight(28);
    infoDescription = new Label();
    infoDescription.setId("search-info-description");
    infoDescription.setWrapText(true);
    infoDescription.setPrefWidth(infoBox.getPrefWidth()-24);
    infoBox.getChildren().addAll(infoName,infoDescription);
    extraInfoPopup.getContent().add(infoBox);
    // hide info popup when context menu is hidden
    contextMenu.setOnHidden(new EventHandler<WindowEvent>() {
        @Override public void handle(WindowEvent windowEvent) {
            extraInfoPopup.hide();
        }
    });
}