Java Code Examples for javafx.scene.layout.Region#setPrefSize()

The following examples show how to use javafx.scene.layout.Region#setPrefSize() . 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: Builders.java    From PDF4Teachers with Apache License 2.0 6 votes vote down vote up
public static void setPosition(Region element, double x, double y, double width, double height, boolean force){

        if(x >= 0){
            element.setLayoutX(x);
        }if(y >= 0){
            element.setLayoutY(y);
        }
        element.setPrefSize(width, height);

        if(force){
            element.setStyle("-fx-min-width: " + width + ";");
            element.setStyle("-fx-min-height: " + height + ";");
            element.minWidthProperty().bind(new SimpleDoubleProperty(width));
            element.minHeightProperty().bind(new SimpleDoubleProperty(height));
        }
    }
 
Example 2
Source File: Demo.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private HBox getCountryItem(final Flag flag, final String text, final String data) {
    ImageView imageView = new ImageView(flag.getImage(22));
    HBox.setHgrow(imageView, Priority.NEVER);

    Label name = new Label(text);
    name.setTextFill(Tile.FOREGROUND);
    name.setAlignment(Pos.CENTER_LEFT);
    HBox.setHgrow(name, Priority.NEVER);

    Region spacer = new Region();
    spacer.setPrefSize(5, 5);
    HBox.setHgrow(spacer, Priority.ALWAYS);

    Label views = new Label(data);
    views.setTextFill(Tile.FOREGROUND);
    views.setAlignment(Pos.CENTER_RIGHT);
    HBox.setHgrow(views, Priority.NEVER);

    HBox hBox = new HBox(5, imageView, name, spacer, views);
    hBox.setAlignment(Pos.CENTER_LEFT);
    hBox.setFillHeight(true);

    return hBox;
}
 
Example 3
Source File: ChargeSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    for (int i = 0 ; i < 12 ; i++) {
        Region bar = new Region();
        bar.setPrefSize(20, 20 + (i * 4));
        bars[i] = bar;
    }

    pane = new HBox(bars);
    pane.setSpacing(PREFERRED_WIDTH * 0.01960784);
    pane.setAlignment(Pos.BOTTOM_CENTER);
    pane.setFillHeight(false);
    pane.setBackground(new Background(new BackgroundFill(backgroundPaint, new CornerRadii(1024), Insets.EMPTY)));
    pane.setBorder(new Border(new BorderStroke(borderPaint, BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(borderWidth))));

    getChildren().setAll(pane);
}
 
Example 4
Source File: FX.java    From FxDock with Apache License 2.0 5 votes vote down vote up
/** creates a fixed spacer */
public static Region spacer(double size)
{
	Region r = new Region();
	r.setMinSize(size, size);
	r.setMaxSize(size, size);
	r.setPrefSize(size, size);
	return r;
}
 
Example 5
Source File: UIUtils.java    From SONDY with GNU General Public License v3.0 5 votes vote down vote up
public static void setSize(final Region region, int width, int height){
    region.setPrefSize(width, height);
    region.setMinWidth(width);
    region.setMaxWidth(width);
    region.setMinHeight(height);
    region.setMaxHeight(height);
}
 
Example 6
Source File: VuMeterSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void resize() {
    size = getSkinnable().getWidth() < getSkinnable().getHeight() ? getSkinnable().getWidth() : getSkinnable().getHeight();                       
    if (size > 0) {                        
        for (Region led : leds) {
            led.setPrefSize(size, size);
        }                                        
    }
}
 
Example 7
Source File: SlideCheckBoxSkin.java    From JFX8CustomControls with Apache License 2.0 5 votes vote down vote up
private void initGraphics() {
    markBox = new Region();
    markBox.getStyleClass().setAll("mark");
    markBox.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
    markBox.setTranslateX(-27);

    crossBox = new Region();
    crossBox.getStyleClass().setAll("cross");
    crossBox.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
    crossBox.setTranslateX(27);

    thumb = new Region();
    thumb.getStyleClass().setAll("thumb");
    thumb.setMinSize(48, 34);
    thumb.setPrefSize(48, 34);
    thumb.setMaxSize(48, 34);

    if (getSkinnable().isSelected()) {
        crossBox.setOpacity(0);
        thumb.setTranslateX(24);
    } else {
        markBox.setOpacity(0);
        thumb.setTranslateX(-24);
    }

    box.getStyleClass().setAll("box");
    box.getChildren().addAll(markBox, crossBox, thumb);
    updateChildren();
}
 
Example 8
Source File: SearchBox.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void populateMenu(Map<DocumentType, List<SearchResult>> results) {
    contextMenu.getItems().clear();
    for (Map.Entry<DocumentType, List<SearchResult>> entry : results.entrySet()) {
        boolean first = true;
        for(SearchResult result: entry.getValue()) {
            final SearchResult sr = result;
            final HBox hBox = new HBox();
            hBox.setFillHeight(true);
            Label itemLabel = new Label(result.getName());
            itemLabel.getStyleClass().add("item-label");
            if (first) {
                first = false;
                Label groupLabel = new Label(result.getDocumentType().getPluralDisplayName());
                groupLabel.getStyleClass().add("group-label");
                groupLabel.setAlignment(Pos.CENTER_RIGHT);
                groupLabel.setMinWidth(USE_PREF_SIZE);
                groupLabel.setPrefWidth(70);
                hBox.getChildren().addAll(groupLabel,itemLabel);
            } else {
                Region spacer = new Region();
                spacer.setMinWidth(USE_PREF_SIZE);
                spacer.setPrefWidth(70);
                hBox.getChildren().addAll(spacer,itemLabel);
            }
            // create a special node for hiding/showing popup content
            final Region popRegion = new Region();
            popRegion.getStyleClass().add("search-menu-item-popup-region");
            popRegion.setPrefSize(10, 10);
            hBox.getChildren().add(popRegion);
            final String name = (result.getDocumentType() == DocumentType.SAMPLE) ? result.getName() :
                    result.getPackageName()+
                            ((result.getClassName() != null) ? "."+result.getClassName() : "") +
                            ((result.getName() != null) ? "."+result.getName() : "");
            final String shortDescription = (result.getShortDescription().length() == 160) ? result.getShortDescription() +"..." : result.getShortDescription();
            popRegion.opacityProperty().addListener(new ChangeListener<Number>() {
                @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                    Platform.runLater( new Runnable() { // TODO runLater used here as a workaround for RT-14396
                        @Override public void run() {
                            if (popRegion.getOpacity() == 1) {
                                infoName.setText(name);
                                infoDescription.setText(shortDescription);
                                Point2D hBoxPos = hBox.localToScene(0, 0);
                                extraInfoPopup.show(getScene().getWindow(),
                                    hBoxPos.getX() + contextMenu.getScene().getX() + contextMenu.getX() - infoBox.getPrefWidth() - 10,
                                    hBoxPos.getY() + contextMenu.getScene().getY() + contextMenu.getY() - 27
                                );
                            }
                        }
                    });
                }
            });
            // create menu item
            CustomMenuItem menuItem = new CustomMenuItem(hBox, true);
            menuItem.getStyleClass().add("search-menu-item");
            contextMenu.getItems().add(menuItem);
            // handle item selection
            menuItem.setOnAction(new EventHandler<ActionEvent>() {
                @Override public void handle(ActionEvent actionEvent) {
                    ///System.out.println("SearchBox.handle menuItem.setOnAction");
                    Ensemble2.getEnsemble2().goToPage(sr.getEnsemblePath(),true);
                }
            });
        }
    }
}
 
Example 9
Source File: SearchBox.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void populateMenu(Map<DocumentType, List<SearchResult>> results) {
    contextMenu.getItems().clear();
    for (Map.Entry<DocumentType, List<SearchResult>> entry : results.entrySet()) {
        boolean first = true;
        for(SearchResult result: entry.getValue()) {
            final SearchResult sr = result;
            final HBox hBox = new HBox();
            hBox.setFillHeight(true);
            Label itemLabel = new Label(result.getName());
            itemLabel.getStyleClass().add("item-label");
            if (first) {
                first = false;
                Label groupLabel = new Label(result.getDocumentType().getPluralDisplayName());
                groupLabel.getStyleClass().add("group-label");
                groupLabel.setAlignment(Pos.CENTER_RIGHT);
                groupLabel.setMinWidth(USE_PREF_SIZE);
                groupLabel.setPrefWidth(70);
                hBox.getChildren().addAll(groupLabel,itemLabel);
            } else {
                Region spacer = new Region();
                spacer.setMinWidth(USE_PREF_SIZE);
                spacer.setPrefWidth(70);
                hBox.getChildren().addAll(spacer,itemLabel);
            }
            // create a special node for hiding/showing popup content
            final Region popRegion = new Region();
            popRegion.getStyleClass().add("search-menu-item-popup-region");
            popRegion.setPrefSize(10, 10);
            hBox.getChildren().add(popRegion);
            final String name = (result.getDocumentType() == DocumentType.SAMPLE) ? result.getName() :
                    result.getPackageName()+
                            ((result.getClassName() != null) ? "."+result.getClassName() : "") +
                            ((result.getName() != null) ? "."+result.getName() : "");
            final String shortDescription = (result.getShortDescription().length() == 160) ? result.getShortDescription() +"..." : result.getShortDescription();
            popRegion.opacityProperty().addListener(new ChangeListener<Number>() {
                @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                    Platform.runLater( new Runnable() { // TODO runLater used here as a workaround for RT-14396
                        @Override public void run() {
                            if (popRegion.getOpacity() == 1) {
                                infoName.setText(name);
                                infoDescription.setText(shortDescription);
                                Point2D hBoxPos = hBox.localToScene(0, 0);
                                extraInfoPopup.show(getScene().getWindow(),
                                    hBoxPos.getX() + contextMenu.getScene().getX() + contextMenu.getX() - infoBox.getPrefWidth() - 10,
                                    hBoxPos.getY() + contextMenu.getScene().getY() + contextMenu.getY() - 27
                                );
                            }
                        }
                    });
                }
            });
            // create menu item
            CustomMenuItem menuItem = new CustomMenuItem(hBox, true);
            menuItem.getStyleClass().add("search-menu-item");
            contextMenu.getItems().add(menuItem);
            // handle item selection
            menuItem.setOnAction(new EventHandler<ActionEvent>() {
                @Override public void handle(ActionEvent actionEvent) {
                    ///System.out.println("SearchBox.handle menuItem.setOnAction");
                    Ensemble2.getEnsemble2().goToPage(sr.getEnsemblePath(),true);
                }
            });
        }
    }
}