Skip to content

Commit 10849d9

Browse files
authored
RFE: Auto height (#944)
Added auto height property and functionality
1 parent bec3e38 commit 10849d9

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,40 @@ public void dispose() {
14441444
* *
14451445
* ********************************************************************** */
14461446

1447+
private BooleanProperty autoHeightProp = new SimpleBooleanProperty();
1448+
1449+
public BooleanProperty autoHeightProperty() {
1450+
return autoHeightProp;
1451+
}
1452+
public void setAutoHeight( boolean value ) {
1453+
autoHeightProp.set( value );
1454+
}
1455+
public boolean isAutoHeight() {
1456+
return autoHeightProp.get();
1457+
}
1458+
1459+
@Override
1460+
protected double computePrefHeight( double width )
1461+
{
1462+
if ( autoHeightProp.get() )
1463+
{
1464+
if ( getWidth() == 0.0 ) Platform.runLater( () -> requestLayout() );
1465+
else
1466+
{
1467+
double height = 0.0;
1468+
Insets in = getInsets();
1469+
1470+
for ( int p = 0; p < getParagraphs().size(); p++ ) {
1471+
height += getCell( p ).getHeight();
1472+
}
1473+
if ( height > 0.0 ) {
1474+
return height + in.getTop() + in.getBottom();
1475+
}
1476+
}
1477+
}
1478+
return super.computePrefHeight( width );
1479+
}
1480+
14471481
@Override
14481482
protected void layoutChildren() {
14491483
Insets ins = getInsets();

0 commit comments

Comments
 (0)