java


How to listen to changes made on javafx choicebox


I have a custom ChoiceBox which I am filling dynamically like so:
public class CustomChoiceBox {
public void addItems(List<Item> items) {
// Populate choicebox
for(Item item : items) {
CustomOption choice = new CustomOption(String.valueOf(item.getId()), item);
this.getItems().add(choice);
}
}
}
CustomOption is a custom class defined as below:
public class CustomOption extends Observable{
private String key;
private Object value;
public CustomOption(String key, Object value) {
this.key = key;
this.value = value;
}
}
I want to be able to listen to when the user makes a different choice and to get the value of that choice.
So I have added a listener :
myChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<CustomOption>() {
#Override
public void changed(ObservableValue<? extends CustomOption> observable,
CustomOption oldValue, CustomOption newValue) {
System.out.println(newVaue.getValue());
}
});
However this code is not running when I change the choices.
I have also tried using myChoiceBox.valueProperty()

Related Links

remove components from a JPanel and add them
Variable not initialized error?
Trying to connect to a remote JVM through JConsole
Algorithm for TripleSum Calculation O(n) time, Java
Modifying field in abstract class using reflection
how to redirect in jsp using <jsp:forward> with a relative url
SoundCloud Play and Like Counts
Windows FileChooser Or Save File Dialog Handling Using JACOB Or JNA
adding values in a hashmap from lisked lists
Formula fails if variables are null
Using Singleton Design with Inheritance in a multithreaded Application
add item to JComboBox from another JDialog
How to create bean of Java class ScheduledThreadPoolExecutor
JavaFX - can't link controller with data array
IOException:cannot run program:CreateProcess error=193,%1 is not a valid Win32 application
GUI with 3 Jbuttons, and a list that stores the selected buttons/list parameters and can display them separately

Categories

HOME
compiler-construction
arduino-uno
multithreading
vbscript
magnific-popup
plot
relay
xmpp
installshield
flyway4
esper
add
correlation
fallback
quickfix
transformation
propel
nhibernate-envers
introduction
reverse-proxy
riot.js
cloudhub
mustache.php
php-openssl
trading
numerical-methods
fish
assistant
quote
r-raster
key-value-observing
galsim
azure-sql-database
ghost4j
io-redirection
dartium
abstract-class
document.write
streamreader
elasticsearch-plugin
ncalc
botbuilder
fakeiteasy
skeleton-css-boilerplate
dotcover
pubmed
jquery-validate
logparser
crypt
libusb-win32
boost-preprocessor
epson
dwscript
gnome-shell-extensions
jquery-filter
tcpserver
sdhc
intellij-14
mutation-observers
security-testing
appfabric-cache
unity3d-gui
ami
composite
web-controls
sonarqube5.1.2
graph-api-explorer
truevault
umbraco6
dd
gadt
mdt
project-planning
tld
mechanize-ruby
balanced-payments
prettify
terminal-services
google-cloud-save
ril
sqlperformance
android-screen-support
kyotocabinet
chrono
amazon-appstore
radcombobox
fluent-interface
.nettiers
gamma
nsviewanimation
memory-size
ti-dsp
privilege
temporal-database
text-coloring
genealogy
grid-system
django-notification

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App