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

The following examples show how to use javafx.scene.layout.Region#setPrefHeight() . 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 setHBoxPosition(Region element, double width, double height, Insets margin){

        if(width == -1){
            HBox.setHgrow(element, Priority.ALWAYS);
            element.setMaxWidth(Double.MAX_VALUE);
        }else if(width != 0){
            element.setPrefWidth(width);
            element.minWidthProperty().bind(new SimpleDoubleProperty(width));
        }
        if(height == -1){
            VBox.setVgrow(element, Priority.ALWAYS);
        }else if(height != 0){
            element.setPrefHeight(height);
            element.minHeightProperty().bind(new SimpleDoubleProperty(height));
        }
        HBox.setMargin(element, margin);
    }
 
Example 2
Source File: Builders.java    From PDF4Teachers with Apache License 2.0 6 votes vote down vote up
public static void setVBoxPosition(Region element, double width, double height, Insets margin){

        if(width == -1){
            HBox.setHgrow(element, Priority.ALWAYS);
            element.setMaxWidth(Double.MAX_VALUE);
        }else if(width != 0){
            element.setPrefWidth(width);
            element.minWidthProperty().bind(new SimpleDoubleProperty(width));
        }
        if(height == -1){
            VBox.setVgrow(element, Priority.ALWAYS);
        }else if(height != 0){
            element.setPrefHeight(height);
            element.minHeightProperty().bind(new SimpleDoubleProperty(height));
        }
        VBox.setMargin(element, margin);
    }
 
Example 3
Source File: CellGestures.java    From fxgraph with Do What The F*ck You Want To Public License 5 votes vote down vote up
private static void dragNorth(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) {
	final double deltaY = event.getSceneY() - mouseLocation.value.getY();
	final double newY = region.getLayoutY() + deltaY;
	if(newY != 0 && newY >= handleRadius && newY <= region.getLayoutY() + region.getHeight() - handleRadius) {
		region.setLayoutY(newY);
		region.setPrefHeight(region.getPrefHeight() - deltaY);
	}
}
 
Example 4
Source File: CellGestures.java    From fxgraph with Do What The F*ck You Want To Public License 5 votes vote down vote up
private static void dragSouth(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) {
	final double deltaY = event.getSceneY() - mouseLocation.value.getY();
	final double newMaxY = region.getLayoutY() + region.getHeight() + deltaY;
	if(newMaxY >= region.getLayoutY() && newMaxY <= region.getParent().getBoundsInLocal().getHeight() - handleRadius) {
		region.setPrefHeight(region.getPrefHeight() + deltaY);
	}
}
 
Example 5
Source File: Loading.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public Loading(URL imageUrl) {
    super();
    // 设置背景颜色
    setBackgroundColor(20,20,20,0.5f);
    contentBox = new VBox();

    // 间隔
    Region topRegion = new Region();
    topRegion.setPrefHeight(20);
    contentBox.getChildren().add(topRegion);

    // gif动态图
    imageView = new ImageView();
    imageView.setSmooth(true);
    setImage(imageUrl);
    contentBox.getChildren().add(imageView);

    // 间隔
    Region region = new Region();
    region.setPrefHeight(15);
    contentBox.getChildren().add(region);

    // 提示信息
    text = new Text();
    text.setStyle("-fx-fill: white; -fx-font-size:24;");
    contentBox.getChildren().add(text);

    // 设置内容居中
    contentBox.alignmentProperty().set(Pos.CENTER);
    // 设置布局居中
    setAlignment(contentBox,Pos.CENTER);
    getChildren().add(contentBox);
}
 
Example 6
Source File: JFXUtil.java    From jfxutils with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a "Scale Pane", which is a pane that scales as it resizes, instead of reflowing layout
 * like a normal pane. It can be used to create an effect like a presentation slide. There is no
 * attempt to preserve the aspect ratio.
 * <p>
 * If the region has an explicitly set preferred width and height, those are used unless
 * override is set true.
 * <p>
 * If the region already has a parent, the returned pane will replace it via the
 * {@link #replaceComponent(Node, Node)} method. The Region's parent must be a Pane in this case.
 *
 * @param region   non-null Region
 * @param w        default width, used if the region's width is calculated
 * @param h        default height, used if the region's height is calculated
 * @param override if true, w,h is the region's "100%" size even if the region has an explicit
 *                 preferred width and height set.
 *
 * @return the created StackPane, with preferred width and height set based on size determined by
 *         w, h, and override parameters.
 */
public static StackPane createScalePane( Region region, double w, double h, boolean override ) {
	//If the Region containing the GUI does not already have a preferred width and height, set it.
	//But, if it does, we can use that setting as the "standard" resolution.
	if ( override || region.getPrefWidth() == Region.USE_COMPUTED_SIZE )
		region.setPrefWidth( w );
	else
		w = region.getPrefWidth();

	if ( override || region.getPrefHeight() == Region.USE_COMPUTED_SIZE )
		region.setPrefHeight( h );
	else
		h = region.getPrefHeight();

	StackPane ret = new StackPane();
	ret.setPrefWidth( w );
	ret.setPrefHeight( h );
	if ( region.getParent() != null )
		replaceComponent( region, ret );

	//Wrap the resizable content in a non-resizable container (Group)
	Group group = new Group( region );
	//Place the Group in a StackPane, which will keep it centered
	ret.getChildren().add( group );

	//Bind the scene's width and height to the scaling parameters on the group
	group.scaleXProperty().bind( ret.widthProperty().divide( w ) );
	group.scaleYProperty().bind( ret.heightProperty().divide( h ) );

	return ret;
}