• 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

JavaFX Combobox not displaying selected value when closed

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all I have an interesting issue. Seems I am not able to get my code to select the currently selected value. I have a focus and change event on it and it does fire off those just fine. however, it never displays the selected value once the combobox closes.


The App Settings sliders and the Populate Email button are outside of the tabPane. The Extract Type combobox is within the tabPane.

Only time it starts to work normally is when i click outside the tabPane and click a button or something like that. After doing that it will show the selected value. if I then select another value from the dropdown it now shows what I have selected.

BUT! There is another tab that I have the same combobox on and it works as it should...


What setting am I missing here?



I've tried a lot of ways to select the value to show it but nothing above seems to work. Whenever I try to check what the value is (tab_extract_info_cbo_Extract_Type.getValue()) it always gives me the correct value even though its not showing up in the combobox.

The FXML for looks like this:
 
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think what you've provided has enough context to determine what's happening. Maybe something focus related you're doing elsewhere. Are you binding the value of the ComboBox to OC's extractType value or something (which changes on focus...)?

I wouldn't use a focus listener anyway. I would instead watch valueProperty. (Although there are other options too.)


If you're still stuck, what are you initializing the ComboBox with? I guess it's a list of Strings containing numbers? I used int (autoboxed to Integers) above but it's basically the same.
 
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
Also:

It's a good idea to specify the generic type of the ComboBox. It helps the IDE's autocompletion in addition to adding compile time type safety. Yours might be ComboBox<String> but maybe ComboBox<Integer>.

And a nitpick, your naming convention is too snakey (horrible Python-ish underscores! haha):

is normally lowerCamelCase in Java:

(which I would try to also shorten if you can, ex. extractTypeCbx) (and don't forget to change the fx:id in the .fxml to match so your @FXML injection still works)
 
No. No. No. No. Changed my mind. Wanna come down. To see 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