PDA

View Full Version : Textfield property


mohammed_BEY
Sep 22, 2015, 06:09 AM
Hello,
I am working on a project made in Java. I want that the width of the textfield change dynamicaly with the text.
This is the code I used it and longChar (String str) return a double according the length of the string 'str'.
The problem: the textfield doesn't show what I am writing even the width changes.


Can any one hepls me ?
Thank you.


tField2.textProperty().addListener((ObservableValu e<? Extends String> ov, String t, String t1) -> {
tField2.setPrefWidth(longChar(tField2.getText()));
});

CravenMorhead
Sep 22, 2015, 09:58 AM
The width changes but the text doesn't show up. The problem is likely that you changed the path the code follows when you change the field.

Example:

User presses key-> internal string changes -> field redrawn with new text
Could have been changed to:
User presses key -> internal string changes -> field redrawn with new width.
Where you want:
User presses key -> internal string changes -> field redrawn with new width && field redrawn with new text.

Look at your code to see if you need to call the update text or redraw or whatnot.