FXMisc/RichTextFX

getTotalAreaWidthEstimate()

williamclocksin opened this issue · 1 comments

I am using InlineCssTextArea, and as characters are added, I wish to enlarge the area and the box that contains it so that all the characters are shown. And shrink it when characters are deleted. The box must be a tight boundary for the area's contents. I thought area.get TotalWidthEstimate() might be the way to measure the width of the contents, but it returns 15.0 no matter what is in the area. The area's preferred width is 64. Is there something I should call to get a valid total width? Is this documented anywhere? And is there a forum for questions like this so it is not flagged as an Issue? Thanks.

Jugen commented

For a single line of text you could try the following:

var tf = new InlineCssTextField( "Test" );

tf.maxWidthProperty().bind( Bindings.createDoubleBinding( () ->
{
    var charBounds = tf.getCharacterBoundsOnScreen( 0, tf.getLength() );
    if ( charBounds.isEmpty() ) return tf.getPrefWidth();

    var pad = tf.getInsets();
    var width = charBounds.get().getWidth();

    return pad.getLeft() + width + pad.getRight();
},
tf.lengthProperty(), tf.insetsProperty() ));

I've opened a discussion area here, see if that works. I've never used it before, so ..... ?