Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Textfield property (https://www.askmehelpdesk.com/showthread.php?t=816390)

  • Sep 22, 2015, 06:09 AM
    mohammed_BEY
    Textfield property
    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()));
    });
  • Sep 22, 2015, 09:58 AM
    CravenMorhead
    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.

  • All times are GMT -7. The time now is 11:56 AM.