2 spinners that can't "cross their values" in Java Swing.

Hello, I have a problem regarding 2 Spinner that are meant to not "cross their values" (Spinner A's value can't go any higher than spinner's B value, and spinner's B value can't go lower than spinner's A value). Here's my code for those 2 spinners.
private void jSpinnerXBStateChanged(javax.swing.event.ChangeEvent evt) {
zakresXA = (float) jSpinnerXA.getValue();
zakresXB = (float) jSpinnerXB.getValue();
if (!(zakresXA < zakresXB)) {
JOptionPane.showMessageDialog(mainOkno.this,
"Wartość górnego zakresu X nie może być mniejsza od dolnej lub jej równa",
"Błąd", JOptionPane.WARNING_MESSAGE);
}
}

private void jSpinnerXAStateChanged(javax.swing.event.ChangeEvent evt) {
zakresXA = (float) jSpinnerXA.getValue();
zakresXB = (float) jSpinnerXB.getValue();
if (!(zakresXA < zakresXB)) {
JOptionPane.showMessageDialog(mainOkno.this,
"Wartość dolnego zakresu X nie może być większa od górnej lub jej równa",
"Błąd", JOptionPane.WARNING_MESSAGE);
}
}
private void jSpinnerXBStateChanged(javax.swing.event.ChangeEvent evt) {
zakresXA = (float) jSpinnerXA.getValue();
zakresXB = (float) jSpinnerXB.getValue();
if (!(zakresXA < zakresXB)) {
JOptionPane.showMessageDialog(mainOkno.this,
"Wartość górnego zakresu X nie może być mniejsza od dolnej lub jej równa",
"Błąd", JOptionPane.WARNING_MESSAGE);
}
}

private void jSpinnerXAStateChanged(javax.swing.event.ChangeEvent evt) {
zakresXA = (float) jSpinnerXA.getValue();
zakresXB = (float) jSpinnerXB.getValue();
if (!(zakresXA < zakresXB)) {
JOptionPane.showMessageDialog(mainOkno.this,
"Wartość dolnego zakresu X nie może być większa od górnej lub jej równa",
"Błąd", JOptionPane.WARNING_MESSAGE);
}
}
The main problem is that even thought the error pops up the value is still being changed. Let's say my spinner A value is 10 and B is 11. I change the value A to 11.5 than click one more time to increase, error shows up and after i close the dialog the value still increases. I tried to delete and add eventListeners but for some reason i couldn't get it to work.
4 Replies
JavaBot
JavaBot7mo ago
This post has been reserved for your question.
Hey @hemoglobina! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
hemoglobina
hemoglobinaOP7mo ago
I also tried to "cheese it" with just decreasing or increasing value's if they are too low or too high at the end of the functions but changing the value inside this function, call's the function again because the state of the spinner has been changed, thus creating recursion i think.
JavaBot
JavaBot7mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBot7mo ago
Post Closed
This post has been closed by <@292647013240143873>.

Did you find this page helpful?