From 7a3ef0e672bb31d6a51419aa04825c85285f2acf Mon Sep 17 00:00:00 2001 From: Jurgen Date: Wed, 12 Aug 2020 15:22:32 +0200 Subject: [PATCH 1/2] Added auto height property --- .../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..37448a89d 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(); From 346f58ab52e457256be17a9d5deb68a82c137093 Mon Sep 17 00:00:00 2001 From: Jurgen Date: Wed, 12 Aug 2020 15:40:00 +0200 Subject: [PATCH 2/2] Fixup --- .../fxmisc/richtext/GenericStyledArea.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java index 37448a89d..12c229e68 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java @@ -1447,35 +1447,35 @@ public void dispose() { private BooleanProperty autoHeightProp = new SimpleBooleanProperty(); public BooleanProperty autoHeightProperty() { - return autoHeightProp; + return autoHeightProp; } public void setAutoHeight( boolean value ) { - autoHeightProp.set( value ); + autoHeightProp.set( value ); } public boolean isAutoHeight() { - return autoHeightProp.get(); + 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 ); + 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