weixin_39626131
weixin_39626131
2020-12-09 14:51

BigDecimalField - requestFocus is not working

I'm using JFXtras 8.0-r1-SNAPSHOT and I'm having problems using BigDecimalField when I need manipulate focus. The method requestFocus() simply doesn't work. If I need focus in the field I should write this sentence:

((BigDecimalField) field).getChildrenUnmodifiable().get(0).requestFocus();

even this way, the first time I try focus, getChildrenUnmodifiable() returns an empty list.

该提问来源于开源项目:JFXtras/jfxtras-labs

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

12条回答

  • weixin_39857792 weixin_39857792 5月前

    Hi

    I'll have a look into that as soon as time permits.

    Cheers

    Thomas Am 09.05.2014 13:42 schrieb "Hudson Orsine Assumpção" < notifications.com>:

    I'm using JFXtras 8.0-r1-SNAPSHOT and I'm having problems using BigDecimalField when I need manipulate focus. The method requestFocus() simply doesn't work. If I need focus in the field I should write this sentence:

    ((BigDecimalField) field).getChildrenUnmodifiable().get(0).requestFocus();

    even this way, the first time I try focus, getChildrenUnmodifiable() returns an empty list.

    — Reply to this email directly or view it on GitHubhttps://github.com/JFXtras/jfxtras-labs/issues/97 .

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 5月前

    Hudson, I commited a fix and BigDecimalDemo is showcasing the requestFocus() behaviour. It is available with the next nightly build of jfxtras-labs 8.0-r2-SNAPSHOT.

    Cheers

    Thomas

    点赞 评论 复制链接分享
  • weixin_39626131 weixin_39626131 5月前

    Hi Thomas,

    I've updated to version jfxtras-labs 8.0-r2-SNAPSHOT and ran your demo. In your demo the requestFocus is running very well, however, in my code this isn't happening. When I call requestFocus() in a BigDecimalField, I know the focus is in BigDecimalField, however I can't see the cursor and I can't edit the field. Looking at your demo, the unique difference is that the BigDecimalField is instantiated by FXML file. Could this be the problem?

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 5月前

    Hi Hudson,

    I am using it in my own application within FXML as well and it works both ways (as it should). Please make sure that: you put the requestFocus()-Call in a Platform.runLater (Statement), just to be on the safe side

    
       Platform.runLater(new Runnable() {
    
    
            public void run() {
                txtBigDecimalField.requestFocus();
    
            }
        });
    

    you are using the latest jfxtras-labs r2 build from: https://oss.sonatype.org/content/repositories/snapshots/org/jfxtras/jfxtras-labs/8.0-r2-SNAPSHOT/ private void initFocusSimulation() {

    
        // If the TextField gains/loses focus the style of the CONTROL is changed
        CONTROL.focusedProperty().addListener((ov, wasFocused, isFocused) -> {
            if (isFocused) {
                CONTROL.getStyleClass().add("big-decimal-field-focused");
            } else {
                CONTROL.getStyleClass().remove("big-decimal-field-focused");
            }
        });
        textField.focusedProperty().addListener((ov, wasFocused, isFocused) -> {
            if (isFocused) {
                CONTROL.getStyleClass().add("big-decimal-field-focused");
            } else {
                CONTROL.getStyleClass().remove("big-decimal-field-focused");
            }
        });
    
    }
    

    Hope this helps.

    Cheers

    Thomas

    Hi Thomas,

    I've updated to version jfxtras-labs 8.0-r2-SNAPSHOT and ran your demo. In your demo the requestFocus is running very well, however, in my code this isn't happening. When I call requestFocus() in a BigDecimalField, I know the focus is in BigDecimalField, however I can't see the cursor and I can't edit the field. Looking at your demo, the unique difference is that the BigDecimalField is instantiated by FXML file. Could this be the problem?

    — Reply to this email directly or view it on GitHub.

    点赞 评论 复制链接分享
  • weixin_39626131 weixin_39626131 5月前

    Hi Thomas,

    As I told you, I'm using the last version, the focus is in the BigDecimalField when I call requestFocus, however the cursor isn't in the field, and if I type something, nothing happens. Perhaps is something very specific, so I created a simple maven project to show you the problem I'm experiencing. The zip file can be downloaded at https://www.dropbox.com/s/ailqvqq4a0iacro/spinner-test.zip I tried simplify the class hierachy without change the structure, so you will find some unecessary classes. The relevant part is in the class ControladorDialogoItemDocumento.java

    Cheers

    2014-05-15 6:42 GMT-03:00 Thomas Bolz notifications.com:

    Hi Hudson,

    I am using it in my own application within FXML as well and it works both ways (as it should). Please make sure that: you put the requestFocus()-Call in a Platform.runLater (Statement), just to be on the safe side

    Platform.runLater(new Runnable() {

    public void run() { txtBigDecimalField.requestFocus();

    } }); you are using the latest jfxtras-labs r2 build from: https://oss.sonatype.org/content/repositories/snapshots/org/jfxtras/jfxtras-labs/8.0-r2-SNAPSHOT/ private void initFocusSimulation() {

    // If the TextField gains/loses focus the style of the CONTROL is changed CONTROL.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } }); textField.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } });

    }

    Hope this helps.

    Cheers

    Thomas

    Hi Thomas,

    I've updated to version jfxtras-labs 8.0-r2-SNAPSHOT and ran your demo. In your demo the requestFocus is running very well, however, in my code this isn't happening. When I call requestFocus() in a BigDecimalField, I know the focus is in BigDecimalField, however I can't see the cursor and I can't edit the field. Looking at your demo, the unique difference is that the BigDecimalField is instantiated by FXML file. Could this be the problem?

    — Reply to this email directly or view it on GitHub.

    — Reply to this email directly or view it on GitHubhttps://github.com/JFXtras/jfxtras-labs/issues/97#issuecomment-43189090 .

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 5月前

    Hi Hudson,

    I had a look and on your example and now understand what you mean. The jar-version is in fact ok. The BigDecimalField gets the focus which you will see, when you take away the padding statements in your FXML-code. Next thing is that the fields are not initialized with a number, which means that they contain a null value. But you are right, they do not react on typing digits. I cannot tell you what the problem is and if it is your example or the BigDecimalField. I have to admit that I do not totally understand what your program does and more importantly how it does it, which is due to the fact that the code ist portuguese (?) and I also have the impression that you structure your startup sequence a bit different from what I am normally used too in JavaFX, that might be another reason but also my inability to understand your code. What I also noticed is, that I cannot close/quit/Alt-F4 your program and I did not understand why, just another hint that things are a bit strange here. Nevertheless, the only advice, that I can give you is to trace down the problem by rebuilding your example from the ground up on the basis of a standard JavaFX example. Just start with a simple FXML not using BigDecimal or CSS or anything and a standard startup sequence, then try refining things towards your actually code step by step and understand which part is the reason that things do go wrong. One learning that I can share from my experience with JavaFX when things went wrong or something behaved strange is, that in my case it had almost always to do with the fact that I did something with the GUI without being on the GUI thread (although I thought I was).

    Sorry for being no better help

    Thomas

    Hi Hudson,

    Am 15.05.2014 um 15:03 schrieb Hudson Orsine Assumpção notifications.com:

    Hi Thomas,

    As I told you, I'm using the last version, the focus is in the BigDecimalField when I call requestFocus, however the cursor isn't in the field, and if I type something, nothing happens. Perhaps is something very specific, so I created a simple maven project to show you the problem I'm experiencing. The zip file can be downloaded at https://www.dropbox.com/s/ailqvqq4a0iacro/spinner-test.zip I tried simplify the class hierachy without change the structure, so you will find some unecessary classes. The relevant part is in the class ControladorDialogoItemDocumento.java

    Cheers

    2014-05-15 6:42 GMT-03:00 Thomas Bolz notifications.com:

    Hi Hudson,

    I am using it in my own application within FXML as well and it works both ways (as it should). Please make sure that: you put the requestFocus()-Call in a Platform.runLater (Statement), just to be on the safe side

    Platform.runLater(new Runnable() {

    public void run() { txtBigDecimalField.requestFocus();

    } }); you are using the latest jfxtras-labs r2 build from: https://oss.sonatype.org/content/repositories/snapshots/org/jfxtras/jfxtras-labs/8.0-r2-SNAPSHOT/ private void initFocusSimulation() {

    // If the TextField gains/loses focus the style of the CONTROL is changed CONTROL.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } }); textField.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } });

    }

    Hope this helps.

    Cheers

    Thomas

    Hi Thomas,

    I've updated to version jfxtras-labs 8.0-r2-SNAPSHOT and ran your demo. In your demo the requestFocus is running very well, however, in my code this isn't happening. When I call requestFocus() in a BigDecimalField, I know the focus is in BigDecimalField, however I can't see the cursor and I can't edit the field. Looking at your demo, the unique difference is that the BigDecimalField is instantiated by FXML file. Could this be the problem?

    — Reply to this email directly or view it on GitHub.

    — Reply to this email directly or view it on GitHubhttps://github.com/JFXtras/jfxtras-labs/issues/97#issuecomment-43189090 .

    — Reply to this email directly or view it on GitHub.

    点赞 评论 复制链接分享
  • weixin_39626131 weixin_39626131 5月前

    Hi Thomas,

    I'm here again :) I agree with you, the project I sent you was too complex and the code was in portuguese, so I created a really simply example. You can see the problem executing the example or simply opening JavaFX Scene Builder and previewing the fxml file. The focus will be in the first input field, then press tab and try enter value using the keyboard. The link to acess the project is the same.

    Thanks for your attention

    2014-05-18 15:19 GMT-03:00 Thomas Bolz notifications.com:

    Hi Hudson,

    I had a look and on your example and now understand what you mean. The jar-version is in fact ok. The BigDecimalField gets the focus which you will see, when you take away the padding statements in your FXML-code. Next thing is that the fields are not initialized with a number, which means that they contain a null value. But you are right, they do not react on typing digits. I cannot tell you what the problem is and if it is your example or the BigDecimalField. I have to admit that I do not totally understand what your program does and more importantly how it does it, which is due to the fact that the code ist portuguese (?) and I also have the impression that you structure your startup sequence a bit different from what I am normally used too in JavaFX, that might be another reason but also my inability to understand your code. What I also noticed is, that I cannot close/quit/Alt-F4 your program and I did not understand why, just another hint that things are a bit strange here. Nevertheless, the only advice, that I can give you is to trace down the problem by rebuilding your example from the ground up on the basis of a standard JavaFX example. Just start with a simple FXML not using BigDecimal or CSS or anything and a standard startup sequence, then try refining things towards your actually code step by step and understand which part is the reason that things do go wrong. One learning that I can share from my experience with JavaFX when things went wrong or something behaved strange is, that in my case it had almost always to do with the fact that I did something with the GUI without being on the GUI thread (although I thought I was).

    Sorry for being no better help

    Thomas

    Hi Hudson,

    Am 15.05.2014 um 15:03 schrieb Hudson Orsine Assumpção < notifications.com>:

    Hi Thomas,

    As I told you, I'm using the last version, the focus is in the BigDecimalField when I call requestFocus, however the cursor isn't in the field, and if I type something, nothing happens. Perhaps is something very specific, so I created a simple maven project to show you the problem I'm experiencing. The zip file can be downloaded at https://www.dropbox.com/s/ailqvqq4a0iacro/spinner-test.zip I tried simplify the class hierachy without change the structure, so you will find some unecessary classes. The relevant part is in the class ControladorDialogoItemDocumento.java

    Cheers

    2014-05-15 6:42 GMT-03:00 Thomas Bolz notifications.com:

    Hi Hudson,

    I am using it in my own application within FXML as well and it works both ways (as it should). Please make sure that: you put the requestFocus()-Call in a Platform.runLater (Statement), just to be on the safe side

    Platform.runLater(new Runnable() {

    public void run() { txtBigDecimalField.requestFocus();

    } }); you are using the latest jfxtras-labs r2 build from:

    https://oss.sonatype.org/content/repositories/snapshots/org/jfxtras/jfxtras-labs/8.0-r2-SNAPSHOT/ private void initFocusSimulation() {

    // If the TextField gains/loses focus the style of the CONTROL is changed CONTROL.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } }); textField.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } });

    }

    Hope this helps.

    Cheers

    Thomas

    Hi Thomas,

    I've updated to version jfxtras-labs 8.0-r2-SNAPSHOT and ran your demo. In your demo the requestFocus is running very well, however, in my code this isn't happening. When I call requestFocus() in a BigDecimalField, I know the focus is in BigDecimalField, however I can't see the cursor and I can't edit the field. Looking at your demo, the unique difference is that the BigDecimalField is instantiated by FXML file. Could this be the problem?

    — Reply to this email directly or view it on GitHub.

    — Reply to this email directly or view it on GitHub< https://github.com/JFXtras/jfxtras-labs/issues/97#issuecomment-43189090> .

    — Reply to this email directly or view it on GitHub.

    — Reply to this email directly or view it on GitHubhttps://github.com/JFXtras/jfxtras-labs/issues/97#issuecomment-43447096 .

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 5月前

    Hi Hudson,

    thanks for the small sample. Now it became clear what you experience and that is in fact a bug, which should be fixed now. Try the next automated build that should be available some time tomorrow morning or get the sources and make a local build if you can't wait ;-)

    Cheers

    Thomas

    Am 22.05.2014 16:28, schrieb Hudson Orsine Assumpção:

    Hi Thomas,

    I'm here again :) I agree with you, the project I send you was too complex and the code was in portuguese, so I created a really simply example. You can see the problem executing the example or simply opening JavaFX Scene Builder and previewing the fxml file. The focus will be in the first input field, then press tab and try enter value using the keyboard. The link to acess the project is the same.

    Thanks for your attention

    2014-05-18 15:19 GMT-03:00 Thomas Bolz notifications.com:

    Hi Hudson,

    I had a look and on your example and now understand what you mean. The jar-version is in fact ok. The BigDecimalField gets the focus which you will see, when you take away the padding statements in your FXML-code. Next thing is that the fields are not initialized with a number, which means that they contain a null value. But you are right, they do not react on typing digits. I cannot tell you what the problem is and if it is your example or the BigDecimalField. I have to admit that I do not totally understand what your program does and more importantly how it does it, which is due to the fact that the code ist portuguese (?) and I also have the impression that you structure your startup sequence a bit different from what I am normally used too in JavaFX, that might be another reason but also my inability to understand your code. What I also noticed is, that I cannot close/quit/Alt-F4 your program and I did not understand why, just another hint that things are a bit strange here. Nevertheless, the only advice, that I can give you is to trace down the problem by rebuilding your example from the ground up on the basis of a standard JavaFX example. Just start with a simple FXML not using BigDecimal or CSS or anything and a standard startup sequence, then try refining things towards your actually code step by step and understand which part is the reason that things do go wrong. One learning that I can share from my experience with JavaFX when things went wrong or something behaved strange is, that in my case it had almost always to do with the fact that I did something with the GUI without being on the GUI thread (although I thought I was).

    Sorry for being no better help

    Thomas

    Hi Hudson,

    Am 15.05.2014 um 15:03 schrieb Hudson Orsine Assumpção < notifications.com>:

    Hi Thomas,

    As I told you, I'm using the last version, the focus is in the BigDecimalField when I call requestFocus, however the cursor isn't in the field, and if I type something, nothing happens. Perhaps is something very specific, so I created a simple maven project to show you the problem I'm experiencing. The zip file can be downloaded at https://www.dropbox.com/s/ailqvqq4a0iacro/spinner-test.zip I tried simplify the class hierachy without change the structure, so you will find some unecessary classes. The relevant part is in the class ControladorDialogoItemDocumento.java

    Cheers

    2014-05-15 6:42 GMT-03:00 Thomas Bolz notifications.com:

    Hi Hudson,

    I am using it in my own application within FXML as well and it works both ways (as it should). Please make sure that: you put the requestFocus()-Call in a Platform.runLater (Statement), just to be on the safe side

    Platform.runLater(new Runnable() {

    public void run() { txtBigDecimalField.requestFocus();

    } }); you are using the latest jfxtras-labs r2 build from:

    https://oss.sonatype.org/content/repositories/snapshots/org/jfxtras/jfxtras-labs/8.0-r2-SNAPSHOT/

    private void initFocusSimulation() {

    // If the TextField gains/loses focus the style of the CONTROL is changed CONTROL.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } }); textField.focusedProperty().addListener((ov, wasFocused, isFocused) -> { if (isFocused) { CONTROL.getStyleClass().add("big-decimal-field-focused"); } else { CONTROL.getStyleClass().remove("big-decimal-field-focused"); } });

    }

    Hope this helps.

    Cheers

    Thomas

    Hi Thomas,

    I've updated to version jfxtras-labs 8.0-r2-SNAPSHOT and ran your demo. In your demo the requestFocus is running very well, however, in my code this isn't happening. When I call requestFocus() in a BigDecimalField, I know the focus is in BigDecimalField, however I can't see the cursor and I can't edit the field. Looking at your demo, the unique difference is that the BigDecimalField is instantiated by FXML file. Could this be the problem?

    — Reply to this email directly or view it on GitHub.

    — Reply to this email directly or view it on GitHub< https://github.com/JFXtras/jfxtras-labs/issues/97#issuecomment-43189090> .

    — Reply to this email directly or view it on GitHub.

    — Reply to this email directly or view it on GitHubhttps://github.com/JFXtras/jfxtras-labs/issues/97#issuecomment-43447096 .

    — Reply to this email directly or view it on GitHub https://github.com/JFXtras/jfxtras-labs/issues/97#issuecomment-43895283.

    点赞 评论 复制链接分享
  • weixin_39626131 weixin_39626131 5月前

    Hi Thomas,

    Thank you for solving that problem, but I found another issue :(. Imagine you want add a pane that have a BigDecimalField in a StackPane, then after add the new pane, your code request the focus to this field. Unfortunately, the BigDecimalField don't receives the focus, so if you try insert a value using keyboard nothing happens. You can see the issue in the new sample (the same link).

    Cheers

    Hudson

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 5月前

    Hi Hudson,

    I’m not sure if that is an „issue“. Try replacing the BigDecimalField with a TextField and you will see, that it behaves the same.

    Regards

    Thomas

    Am 30.05.2014 um 21:23 schrieb Hudson Orsine Assumpção notifications.com:

    Hi Thomas,

    Thank you for solving that problem, but I found another issue :(. Imagine you want add a pane that have a BigDecimalField in a StackPane, then after add the new pane, your code request the focus to this field. Unfortunately, the BigDecimalField don't receive the focus, so if you try insert a value using keyboard nothing happens. You can see the issue in the new sample (the same link).

    Cheers

    Hudson

    — Reply to this email directly or view it on GitHub.

    点赞 评论 复制链接分享
  • weixin_39626131 weixin_39626131 5月前

    Didn't noticed this happens with TextField too. Thanks for the help

    点赞 评论 复制链接分享
  • weixin_39559119 weixin_39559119 5月前

    I'm using jfxtras-labs-8.0-r3 and I'm having problems using BigDecimalField when I need to catch the focus event inside the textfield control of the spin button.

    Apparently the event on focus is not fired when I click inside the spinbutton's textfield, and I don't know why. Please help me, tnx.

    点赞 评论 复制链接分享

相关推荐