如果即时通讯要从文本字段中获取文本,则将是这样:
String username = txt_username.getText();
但是如何从ComboBox
获取文本?
我尝试过:
int TableNo = (int)comboBoxOrder.getItems();
答案 0 :(得分:0)
comboBox.getValue()
将返回所选对象,因此您可能想要.toString()
public class MainNoFXML extends Application {
public static void main(String[] args) { launch(args); }
@Override
public void start(Stage primaryStage) {
ComboBox comboBox = new ComboBox(FXCollections.observableArrayList(new String[]{"Monday", "Tuesday", "Wednesday", "Thrusday", "Friday"}));
comboBox.setOnAction(event -> {
System.out.println("Selected:"+comboBox.getValue().toString());
System.out.println("All:"+comboBox.getItems().toString());
});
Scene scene = new Scene(comboBox);
primaryStage.setScene(scene);
primaryStage.show();
}
}