InlineCssTextArea.getTotalWidthEstimate() #1201
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
PS: I tried area.applyCss() before area.getTotalWidthEstimate(), but got the same wrong result. |
Beta Was this translation helpful? Give feedback.
-
PS: Looking at your code, I simply did area.getCharacterBoundsOnScreen(0, area.getLength()) when I update the contents of the area, and I now get correct changes in bounds when I append or delete characters. I will forget about the binding, and just do this. Thanks, Jugen, for getting me started on fixing this! |
Beta Was this translation helpful? Give feedback.
-
Ahh, sorry I didn't mention that the code that I provided would set the area/field width automatically as the contents changes - so no need for calling area.getTotalWidthEstimate(). Anyway glad you came right. Just for other viewers reference here's the code I initially suggested: 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() )); |
Beta Was this translation helpful? Give feedback.
PS: Looking at your code, I simply did area.getCharacterBoundsOnScreen(0, area.getLength()) when I update the contents of the area, and I now get correct changes in bounds when I append or delete characters. I will forget about the binding, and just do this. Thanks, Jugen, for getting me started on fixing this!