How to change the value of combo box when calling a record from db. where in nomal SWING Java i use this code
cmbType.setSelectedItem(model.getValueAt(i, 2).toString());
How to do it on JFX Combo box please help!
Thanks in advance!
The JFXComboBox extends the javafx ComboBox so any example for that should work...
These are the first 3 that popped up in google..
http://stackoverflow.com/questions/36758833/how-to-programmatically-set-a-string-value-in-a-javafx-combobox
http://stackoverflow.com/questions/13483025/javafx-2-combobox-setvalue-does-not-set-cb-text
http://www.java2s.com/Code/Java/JavaFX/SetandgetvalueforComboBox.htm
Well i tried these but it didnt work. What im doing is getting the values from db and setting it on combo box. Like bringing up one record and pushing it inside the text and combo. Text comes right but not combo. When i use the methods in the above links the combo will show blank.
Code i used
cmbType.getSelectionModel().select(new Label(rs.getString("Type")));
cmbType.setValue(new Label(rs.getString("Type")));
Hello,
you need to use JFXComboBox<String> instead of JFXComboBox<Label>, or select the actual node from the items list instead of creating a new node for the selected item.
Regards,
hello admin,
didnt get you here
you need to use JFXComboBox instead of JFXComboBox
sorry the tags got ignored and treated as html tags instead of code.
how can i do that node selection im really sorry for asking dumb questions like this but im a noob here thats why
Hey admin,
It did worked. But now im back to a ealier prob which to make the text white. I used -fx-text-fill: WHITE; but didnt work still black. Can you help me? Thank you very very much.
Found it sorry for bothering :)
this is the code if anyone else needs it in future..
.jfx-combo-box {
-fx-background-color: #263146;
-fx-text-fill: WHITE;
}
.jfx-combo-box .cell:selected{
-fx-background-color: #263146;
-fx-text-fill: WHITE;
}
Most helpful comment
Hello,
you need to use
JFXComboBox<String>instead ofJFXComboBox<Label>, or select the actual node from the items list instead of creating a new node for the selected item.Regards,