• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

ComboBox not seeing events

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I have a defined dialog (anchorpane) where a radio button activates either a choice box or a group of combo boxes. The group of combo boxes define +/- Hour and  minute.

When the values are saved, say + 09 00 and I exit the dialog, then reenter the dialog. If I change the hour, (the minutes clear as intended), then if I select the same minutes 00 the combobox never sees the event. I added onKeyPressed, onKeyReleased, onAction, ChangeListener, but nothing will trigger.

This only happens when you re-enter the dialog, you change the hours and re-select the same minutes. If I select different minutes it works fine. I am at a loss as to why the listener is not being called. I know that when the hour is changed that the minutes combobox is being emptied and the selected index is being reset to -1. Then, the box gets filled with new values. I then select the new minutes 00, but no action is triggered.

 
Saloon Keeper
Posts: 15727
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please share an SSCCE with us? Cut out all the parts that are not relevant to your problem, and also share all the necessary resources with us so that we can run the code ourselves, such as the fxml files.
 
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree a complete example would be helpful. From reading the description, if you're selecting the same value, it's not really a "change" as far as the data model is concerned, so not getting an event makes sense to me. (Although onKeyReleased should probably be working. However I don't recommend using that method anyway because it'll ignore mouse events, and there should be better ways, anyway.)

Some tangental comments that may or may not be useful to you..

1) You might want to consider changing your hour/minute ComboBoxes to a Spinner component type.

2) If you're doing serious work with Date/Time and time zones, I strongly recommend using the java.time api. https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html
Time zone hour offsets are problematic when you drill down into the very complex topic of Date/Time and time zones so depending on your needs, java.time could be a very big deal for you.

3) Normally in a JavaFX FXML controller you initialize by implementing the Initializable interface and then implementing this method, rather than using the constructor:

@Override
public void initialize(URL location, ResourceBundle resources) {
}

Although this only gets called once, so if you need one that gets called manually every time the thing is shown, you might still want an "init()" method or an onShow() or something that you can call at that time. But the key thing with the above method is that all your FXML components have been created and injected at that point via FXMLLoader, which is not the case in the constructor.
 
Michael Peremsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the comments.


@Stephan
Thanks for asking for a demo app, it showed that there may be a bug somewhere within my code.

I ended up creating a quick demo with only 2 combo boxes (with integers) and it seemed to work as expected. I will have to revisit my code in this example.

@Lou Hammer
1) I looked at spinners, but the minutes are in uneven increments 0,30,45. I didn't think that spinners supported that.
3) I am doing this in an Initialize method. [@FXMLprotected void initialize()] FYI, it is recommended not to implement the Initializable interface.

NOTE This interface has been superseded by automatic injection of location and resources properties into the controller. FXMLLoader will now automatically call any suitably annotated no-arg initialize() method defined by the controller. It is recommended that the injection approach be used whenever possible.


 
Michael Peremsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After rewriting the code everything is working as expected. No crunch time this week. The load code is a lot cleaner. There were a couple of minor tweaks to the handlers, a couple of lines.

 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh right I forgot, latest versions are moving away from implementing Initializable - I've seen that message in the docs myself!
Old habits stick with you I guess...

Michael Peremsky wrote:
1) I looked at spinners, but the minutes are in uneven increments 0,30,45. I didn't think that spinners supported that.



I could be wrong or confusing this with another UI framework, but I would be surprised if it can't support that. Usually you give it something like a "value provider" or something similarly named, which you plug into the component to do customized stepping.

Edit: Yeah, it's a "value factory", ex: SpinnerValueFactory.IntegerSpinnerValueFactory
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic