From 10849d95578ef729d8c9bc494905b10fb4d25cc4 Mon Sep 17 00:00:00 2001 From: Jurgen Date: Thu, 13 Aug 2020 13:51:04 +0200 Subject: [PATCH] RFE: Auto height (#944) Added auto height property and functionality --- .../fxmisc/richtext/GenericStyledArea.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java index 269be5928..12c229e68 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java @@ -1444,6 +1444,40 @@ public void dispose() { * * * ********************************************************************** */ + private BooleanProperty autoHeightProp = new SimpleBooleanProperty(); + + public BooleanProperty autoHeightProperty() { + return autoHeightProp; + } + public void setAutoHeight( boolean value ) { + autoHeightProp.set( value ); + } + public boolean isAutoHeight() { + return autoHeightProp.get(); + } + + @Override + protected double computePrefHeight( double width ) + { + if ( autoHeightProp.get() ) + { + if ( getWidth() == 0.0 ) Platform.runLater( () -> requestLayout() ); + else + { + double height = 0.0; + Insets in = getInsets(); + + for ( int p = 0; p < getParagraphs().size(); p++ ) { + height += getCell( p ).getHeight(); + } + if ( height > 0.0 ) { + return height + in.getTop() + in.getBottom(); + } + } + } + return super.computePrefHeight( width ); + } + @Override protected void layoutChildren() { Insets ins = getInsets();