JavaFX和场景生成器不会显示组合框选项

JavaFX和场景生成器不会显示组合框选项,java,javafx,builder,scene,Java,Javafx,Builder,Scene,我在javafx和场景生成器中显示组合框选项时遇到问题 首先,我尝试使用一个数组,我想这是行不通的。然后,我尝试使用ObservableList并创建组合框的实例,如 ComboBox combo = new ComboBox(list); 这仍然不会显示组合框选项。 控制器类: package javafxapplication1; import javafxapplication1.JavaFXApplication1; import java.net.URL; import stati

我在javafx和场景生成器中显示组合框选项时遇到问题

首先,我尝试使用一个数组,我想这是行不通的。然后,我尝试使用ObservableList并创建组合框的实例,如

ComboBox combo = new ComboBox(list);
这仍然不会显示组合框选项。 控制器类:

package javafxapplication1;

import javafxapplication1.JavaFXApplication1;
import java.net.URL;
import static java.util.Collections.list;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javax.lang.model.element.Element;

/**
 *
 * @author KJ4CC
 */
public class FXMLDocumentController implements Initializable {
    ObservableList<String> options = 
    FXCollections.observableArrayList(
        "Option 1",
        "Option 2",
        "Option 3"
    );

    @FXML
    private Label label;
     @FXML
    private TextField dateText;
    @FXML
    private TextField time;
    @FXML
    private ComboBox band;

    public void setTimeDate(){
       JavaFXApplication1 javaFXApp = new JavaFXApplication1();
       dateText.setText(javaFXApp.getDate());

    }

    public void setTime(){
       JavaFXApplication1 javaFXApp = new JavaFXApplication1();
       time.setText(javaFXApp.getTime());

    }
    @Override

    public void initialize(URL url, ResourceBundle rb) {
     band = new ComboBox(options);

    }    

}
FXML


任何帮助都将不胜感激!我对这个场景生成器的东西和使用javafx有点陌生。我只是在摸索。谢谢你的帮助

好的,所以我解决了问题。我正在创建一个组合框的新实例,因此创建了一个空实例。以下是修订工作代码的方法

public void initialize(URL url, ResourceBundle rb) {
         ObservableList<String> options = 
    FXCollections.observableArrayList(
        "Option 1",
        "Option 2",
        "Option 3"
    );
        band.setItems(options);

    }   
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="383.0" prefWidth="590.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication1.FXMLDocumentController">
   <top>
      <VBox prefHeight="235.0" prefWidth="543.0" BorderPane.alignment="CENTER">
         <children>
            <MenuBar>
              <menus>
                <Menu mnemonicParsing="false" text="File">
                  <items>
                    <MenuItem mnemonicParsing="false" text="Close" />
                  </items>
                </Menu>
                <Menu mnemonicParsing="false" text="Edit">
                  <items>
                    <MenuItem mnemonicParsing="false" text="Delete" />
                  </items>
                </Menu>
                <Menu mnemonicParsing="false" text="Help">
                  <items>
                    <MenuItem mnemonicParsing="false" text="About" />
                  </items>
                </Menu>
              </menus>
            </MenuBar>
            <TableView prefHeight="210.0" prefWidth="634.0">
              <columns>
                <TableColumn prefWidth="75.0" text="C1" />
                <TableColumn prefWidth="75.0" text="C2" />
              </columns>
               <VBox.margin>
                  <Insets left="2.0" right="2.0" />
               </VBox.margin>
            </TableView>
         </children>
      </VBox>
   </top>
   <bottom>
      <VBox prefHeight="160.0" prefWidth="676.0" BorderPane.alignment="CENTER">
         <children>
            <HBox prefHeight="22.0" prefWidth="625.0">
               <children>
                  <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Date:" wrappingWidth="83.462890625">
                     <HBox.margin>
                        <Insets left="5.0" right="20.0" />
                     </HBox.margin>
                  </Text>
                  <Label onMouseClicked="#setTimeDate" />
                  <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Time:" wrappingWidth="73.40625" />
                  <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Call:" wrappingWidth="122.94921875">
                     <HBox.margin>
                        <Insets left="5.0" />
                     </HBox.margin>
                  </Text>
                  <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Band:" wrappingWidth="58.443359375" />
                  <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Freq:" wrappingWidth="106.974609375" />
                  <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Location:" />
               </children>
            </HBox>
            <HBox prefHeight="35.0" prefWidth="625.0">
               <children>
                  <TextField id="dateText" fx:id="dateText" prefHeight="25.0" prefWidth="94.0">
                     <HBox.margin>
                        <Insets left="5.0" />
                     </HBox.margin>
                  </TextField>
                  <TextField fx:id="time" layoutX="10.0" layoutY="10.0" prefHeight="25.0" prefWidth="71.0">
                     <padding>
                        <Insets left="5.0" />
                     </padding>
                     <HBox.margin>
                        <Insets left="10.0" right="10.0" />
                     </HBox.margin>
                  </TextField>
                  <TextField layoutX="104.0" layoutY="10.0" prefHeight="25.0" prefWidth="101.0">
                     <HBox.margin>
                        <Insets right="10.0" />
                     </HBox.margin>
                  </TextField>
                  <ComboBox fx:id="band" prefHeight="25.0" prefWidth="57.0">
                     <HBox.margin>
                        <Insets right="10.0" />
                     </HBox.margin>
                  </ComboBox>
                  <TextField layoutX="306.0" layoutY="10.0" prefHeight="25.0" prefWidth="101.0">
                     <HBox.margin>
                        <Insets right="10.0" />
                     </HBox.margin>
                  </TextField>
                  <TextField layoutX="306.0" layoutY="10.0" prefHeight="25.0" prefWidth="101.0" />
               </children>
            </HBox>
            <HBox prefHeight="30.0" prefWidth="580.0">
               <children>
                  <Text fill="#14bdd7" onMouseClicked="#setTimeDate" strokeType="OUTSIDE" strokeWidth="0.0" text="Use Current Date">
                     <HBox.margin>
                        <Insets right="20.0" />
                     </HBox.margin>
                  </Text>
                  <Text fill="#14bdd7" layoutX="10.0" layoutY="23.0" onMouseClicked="#setTime" strokeType="OUTSIDE" strokeWidth="0.0" text="Use Current Time" />
               </children>
            </HBox>
         </children>
         <BorderPane.margin>
            <Insets left="5.0" right="5.0" />
         </BorderPane.margin>
      </VBox>
   </bottom>
</BorderPane>
public void initialize(URL url, ResourceBundle rb) {
         ObservableList<String> options = 
    FXCollections.observableArrayList(
        "Option 1",
        "Option 2",
        "Option 3"
    );
        band.setItems(options);

    }