I am query Sql Server and returning a List - I want to use this List as the source for my combobox. Below is the code that I am using, and it runs error free, but my combobox is always empty and never populated. What is incorrect here?
public class Controller {
private List<String> combomain;
static String getData = "QueryHEre";
void initialize() {
empnames = queryDatabase(getData);
String[] names = empnames.toArray(new String[0]);
combomain.getItems().addAll(names);
combomain.setValue("");
}
Main.java
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 350, 275));
primaryStage.show();
}
sample.fxml
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="399.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<FlowPane hgap="10.0" layoutX="14.0" layoutY="7.0" prefHeight="30.0" prefWidth="375.0">
<children>
<Label alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="79.0" text="Employee:" />
<ComboBox id="combomain" fx:id="combomain" prefWidth="150.0" />
<Button mnemonicParsing="false" prefHeight="27.0" prefWidth="80.0" text="Get Info" />
</children>
</FlowPane>
</children>
</Pane>