如何从java / javafx中该组合框中存在的元素设置组合框的值。这是我迄今为止所做的代码。
package LetMeTest;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXComboBox;
import java.net.URL;
import java.util.ArrayList;
import java.util.Observable;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
public class TryController implements Initializable {
@FXML
private JFXComboBox<?> cb;
@FXML
private JFXButton btnGet;
@FXML
private JFXButton btnSet;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb)
{
ObservableList oo=FXCollections.observableArrayList("b","a");
cb.setItems(oo);
}
@FXML
private void doGetItem(ActionEvent event)
{
System.out.println("Selected Item="+cb.getSelectionModel().getSelectedItem());
}
@FXML
private void doSetItem(ActionEvent event)
{
cb.setValue("b");
}
}
我正在尝试使用ObservableList。告诉我还有其他可能性。