java fx - updating texfield after togglebar change - small bug
I have an issue with below part of code
ArrayList<Integer> baseCost = new ArrayList<>();
priceTextField.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
baseCost.add(Integer.parseInt(priceTextField.getText()));
}
});
daysSlider.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
priceTextField.textProperty().setValue(String.valueOf((int) daysSlider.getValue() * baseCost.get(0)));
};
});
Program works as follows:
I update data in form called addCar.fxml, after clicking saving button car is added to my database. I type digit in textfield, if slider is set to for example 3 textfield number updates automatically to textfield * 3
Slider value has range since 1 to 10
problem:
If I paste the number from the clipboard, for example 500, then slider is 3 I get a value 1500 - which is correct
but if I type number from the keyboard 5+0+0 program read only first digit from the texfield so if slider is 3 then I get result 15
It looks data is pulled after first digit is passed to Textfield, how can I workaround this?
java javafx
add a comment |
I have an issue with below part of code
ArrayList<Integer> baseCost = new ArrayList<>();
priceTextField.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
baseCost.add(Integer.parseInt(priceTextField.getText()));
}
});
daysSlider.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
priceTextField.textProperty().setValue(String.valueOf((int) daysSlider.getValue() * baseCost.get(0)));
};
});
Program works as follows:
I update data in form called addCar.fxml, after clicking saving button car is added to my database. I type digit in textfield, if slider is set to for example 3 textfield number updates automatically to textfield * 3
Slider value has range since 1 to 10
problem:
If I paste the number from the clipboard, for example 500, then slider is 3 I get a value 1500 - which is correct
but if I type number from the keyboard 5+0+0 program read only first digit from the texfield so if slider is 3 then I get result 15
It looks data is pulled after first digit is passed to Textfield, how can I workaround this?
java javafx
1
List.add
adds adds a new element to the list.baseCost.get(0)
always reads the first one...
– fabian
Nov 12 at 19:47
How can we rebuild this logic to still have required result,
– Tomek Młynarski
Nov 12 at 19:54
after typing textfield, then changing slider, textfield updates automatically with logic textfield * slider value
– Tomek Młynarski
Nov 12 at 19:56
Maybe I will just add one more TextField with base price
– Tomek Młynarski
Nov 12 at 21:18
add a comment |
I have an issue with below part of code
ArrayList<Integer> baseCost = new ArrayList<>();
priceTextField.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
baseCost.add(Integer.parseInt(priceTextField.getText()));
}
});
daysSlider.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
priceTextField.textProperty().setValue(String.valueOf((int) daysSlider.getValue() * baseCost.get(0)));
};
});
Program works as follows:
I update data in form called addCar.fxml, after clicking saving button car is added to my database. I type digit in textfield, if slider is set to for example 3 textfield number updates automatically to textfield * 3
Slider value has range since 1 to 10
problem:
If I paste the number from the clipboard, for example 500, then slider is 3 I get a value 1500 - which is correct
but if I type number from the keyboard 5+0+0 program read only first digit from the texfield so if slider is 3 then I get result 15
It looks data is pulled after first digit is passed to Textfield, how can I workaround this?
java javafx
I have an issue with below part of code
ArrayList<Integer> baseCost = new ArrayList<>();
priceTextField.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
baseCost.add(Integer.parseInt(priceTextField.getText()));
}
});
daysSlider.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
priceTextField.textProperty().setValue(String.valueOf((int) daysSlider.getValue() * baseCost.get(0)));
};
});
Program works as follows:
I update data in form called addCar.fxml, after clicking saving button car is added to my database. I type digit in textfield, if slider is set to for example 3 textfield number updates automatically to textfield * 3
Slider value has range since 1 to 10
problem:
If I paste the number from the clipboard, for example 500, then slider is 3 I get a value 1500 - which is correct
but if I type number from the keyboard 5+0+0 program read only first digit from the texfield so if slider is 3 then I get result 15
It looks data is pulled after first digit is passed to Textfield, how can I workaround this?
java javafx
java javafx
edited Nov 12 at 19:39
fabian
50.4k115272
50.4k115272
asked Nov 12 at 19:35
Tomek Młynarski
46
46
1
List.add
adds adds a new element to the list.baseCost.get(0)
always reads the first one...
– fabian
Nov 12 at 19:47
How can we rebuild this logic to still have required result,
– Tomek Młynarski
Nov 12 at 19:54
after typing textfield, then changing slider, textfield updates automatically with logic textfield * slider value
– Tomek Młynarski
Nov 12 at 19:56
Maybe I will just add one more TextField with base price
– Tomek Młynarski
Nov 12 at 21:18
add a comment |
1
List.add
adds adds a new element to the list.baseCost.get(0)
always reads the first one...
– fabian
Nov 12 at 19:47
How can we rebuild this logic to still have required result,
– Tomek Młynarski
Nov 12 at 19:54
after typing textfield, then changing slider, textfield updates automatically with logic textfield * slider value
– Tomek Młynarski
Nov 12 at 19:56
Maybe I will just add one more TextField with base price
– Tomek Młynarski
Nov 12 at 21:18
1
1
List.add
adds adds a new element to the list. baseCost.get(0)
always reads the first one...– fabian
Nov 12 at 19:47
List.add
adds adds a new element to the list. baseCost.get(0)
always reads the first one...– fabian
Nov 12 at 19:47
How can we rebuild this logic to still have required result,
– Tomek Młynarski
Nov 12 at 19:54
How can we rebuild this logic to still have required result,
– Tomek Młynarski
Nov 12 at 19:54
after typing textfield, then changing slider, textfield updates automatically with logic textfield * slider value
– Tomek Młynarski
Nov 12 at 19:56
after typing textfield, then changing slider, textfield updates automatically with logic textfield * slider value
– Tomek Młynarski
Nov 12 at 19:56
Maybe I will just add one more TextField with base price
– Tomek Młynarski
Nov 12 at 21:18
Maybe I will just add one more TextField with base price
– Tomek Młynarski
Nov 12 at 21:18
add a comment |
1 Answer
1
active
oldest
votes
Not an answer to your problem, but wouldn't a label to display price * days be a lot simpler and more intuitive from the user's perspective? Why do you want to change the text field directly?
To answer your question, change baseCost to be an int instead of a List. (I still can't quite figure out why you would need a List here, unless I'm missing something)
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 13 at 22:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268951%2fjava-fx-updating-texfield-after-togglebar-change-small-bug%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not an answer to your problem, but wouldn't a label to display price * days be a lot simpler and more intuitive from the user's perspective? Why do you want to change the text field directly?
To answer your question, change baseCost to be an int instead of a List. (I still can't quite figure out why you would need a List here, unless I'm missing something)
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 13 at 22:03
add a comment |
Not an answer to your problem, but wouldn't a label to display price * days be a lot simpler and more intuitive from the user's perspective? Why do you want to change the text field directly?
To answer your question, change baseCost to be an int instead of a List. (I still can't quite figure out why you would need a List here, unless I'm missing something)
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 13 at 22:03
add a comment |
Not an answer to your problem, but wouldn't a label to display price * days be a lot simpler and more intuitive from the user's perspective? Why do you want to change the text field directly?
To answer your question, change baseCost to be an int instead of a List. (I still can't quite figure out why you would need a List here, unless I'm missing something)
Not an answer to your problem, but wouldn't a label to display price * days be a lot simpler and more intuitive from the user's perspective? Why do you want to change the text field directly?
To answer your question, change baseCost to be an int instead of a List. (I still can't quite figure out why you would need a List here, unless I'm missing something)
answered Nov 12 at 20:54
Gnas
49829
49829
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 13 at 22:03
add a comment |
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 13 at 22:03
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 13 at 22:03
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 13 at 22:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268951%2fjava-fx-updating-texfield-after-togglebar-change-small-bug%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
List.add
adds adds a new element to the list.baseCost.get(0)
always reads the first one...– fabian
Nov 12 at 19:47
How can we rebuild this logic to still have required result,
– Tomek Młynarski
Nov 12 at 19:54
after typing textfield, then changing slider, textfield updates automatically with logic textfield * slider value
– Tomek Młynarski
Nov 12 at 19:56
Maybe I will just add one more TextField with base price
– Tomek Młynarski
Nov 12 at 21:18