weixin_39653764
weixin_39653764
2021-01-12 15:58

Problem with JFXTextField validator and requestFocus()

Hi, i have a problem when I call the requestfocus () method on a JFXTextField with LabelFloat true that is validated. When I have the focus on the textfield and with a button I call the textField requestFocus () method the problem arises, the LabelFloat drops down and stays there until I again focus on JFXTextField. deepinscreenshot_20170917052144-iloveimg-cropped

What I want to do, is to validate the textfield and at the same time make a requestFocus () to the same textfield.

Method for validation:


txtLastName.focusedProperty().addListener((o, oldVal, newVal) -> {
            if (!newVal) txtLastName.validate();
        })

Try to separate the call to the validate, executing it together with the requestFocus () method, but the result is the same



txtLastName.validate();
txtLastName.requestFocus();

该提问来源于开源项目:jfoenixadmin/JFoenix

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39653764 weixin_39653764 4月前

    I'm using the version 1.8 of Maven. Thanks

    点赞 评论 复制链接分享
  • weixin_39942492 weixin_39942492 4月前

    Hello, We were not able to reproduce the issue, can you provide a sample code demonstrating the issue?

    Regards,

    点赞 评论 复制链接分享
  • weixin_39653764 weixin_39653764 4月前

    This happens when I call the resetValidation () method and I click the button quickly. This is the code I have:

    
    txtTest.focusedProperty().addListener((o, oldVal, newVal) -> {
                if (!newVal) {
                    txtTest.validate();
                }
            });
    
            btnTest.setOnAction(e -> {
                txtTest.resetValidation();
                txtTest.requestFocus();
            });
    
    点赞 评论 复制链接分享
  • weixin_39653764 weixin_39653764 4月前

    Also tested with the following code, and the error comes out on the first try when you press the button (remember that the click on the button has to be fast, because if you keep the focus on the button does not show the problem):

    
    btnAction.setOnAction(e -> {
       txtTest.resetValidation();
       txtTest.validate();
       txtTest.requestFocus();
    });
    
    点赞 评论 复制链接分享
  • weixin_39942492 weixin_39942492 4月前

    Hello, still not able to reproduce, can you provide the full code?

    Regards,

    点赞 评论 复制链接分享
  • weixin_39653764 weixin_39653764 4月前

    There are two blocks of code in the controller, each one shows the same problem but in different implementation, I hope this works :D.

    https://github.com/TioCoding/JFoenixTest

    (When running, press the button first and then type in the textfield)

    点赞 评论 复制链接分享
  • weixin_39942492 weixin_39942492 4月前

    Hello, We were able to reproduce the issue in the example you provided. it's fixed by using AnimationTimer instead of Transitions/Timelines.

    Thanks for pointing out the issue 👍 , the fix will be pushed to maven central by the end of the month in JFoenix 1.9. Meanwhile you can get it by download JFoenix jar from the website.

    Regards,

    点赞 评论 复制链接分享

相关推荐