Eu preciso colocar uma lista que eu criei num combobox no javafx,
A lista
`public class Person {
private final StringProperty firstName;
private final StringProperty email;
private final StringProperty telefone;
/**
* Default constructor.
*/
public Person() {
this(null);
}
/**
* Constructor with some initial data.
*
* @param firstName
*/
public Person(String firstName) {
this.firstName = new SimpleStringProperty(firstName);
this.email = new SimpleStringProperty("");
this.telefone = new SimpleStringProperty("");
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String firstName) {
this.firstName.set(firstName);
}
public StringProperty firstNameProperty() {
return firstName;
}
public String getEmail() {
return email.get();
}
public void setEmail(String email) {
this.email.set(email);
}
public StringProperty emailProperty() {
return email;
}
public String getTelefone() {
return telefone.get();
}
public void setTelefone(String telefone) {
this.telefone.set(telefone);
}
public StringProperty telefoneProperty() {
return telefone;
}
}`
`public class PersonOverviewController{
ObservableList<String> lista_mes=FXCollections.observableArrayList(
"Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto"
,"Setembro","Outubro","Novembro","Dezembro");
@FXML
private TableView<Person> personTable;
@FXML
private TableColumn<Person, String> firstNameColumn;
@FXML
private TableView<Person> personTable2;
@FXML
private TableColumn<Person, String> FirstNameColumn2;
@FXML
private Label firstNameLabel;
@FXML
private Label email;
@FXML
private Label telefone;
@FXML
private ComboBox<String> sel_mes;
@FXML
private ComboBox<String> sel_nome;
// Reference to the main application.
private MainApp mainApp;
@FXML
private void initialize(){
// Inicializa a tabela de pessoas com duas colunas.
firstNameColumn.setCellValueFactory(
cellData -> cellData.getValue().firstNameProperty());
showPersonDetails(null);
String nome_mes = null;
sel_mes.setValue("Janeiro");
sel_mes.setItems(lista_mes);
// sel_nome.setItems(lista_nome);
// Detecta mudanças de seleção e mostra os detalhes da pessoa quando houver mudança.
personTable.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue) -> showPersonDetails(newValue));
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
personTable.setItems(mainApp.getPersonData());
}
private void showPersonDetails(Person person) {
if (person != null) {
// Fill the labels with info from the person object.
firstNameLabel.setText(person.getFirstName());
email.setText(person.getEmail());
telefone.setText(person.getTelefone());
} else {
// Person is null, remove all the text.
firstNameLabel.setText("");
email.setText("");
telefone.setText("");
}
}
@FXML
private void handleDeletePerson() {
int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
if (selectedIndex >= 0) {
personTable.getItems().remove(selectedIndex);
} else {
// Nada selecionado.
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Excluir");
alert.setHeaderText(null);
alert.setContentText("Selecione uma pessoa por favor!");
alert.showAndWait();
}
}
/**
* Called when the user clicks the new button. Opens a dialog to edit
* details for a new person.
*/
@FXML
private void handleNewPerson() {
Person tempPerson = new Person();
boolean okClicked = mainApp.showPersonEditDialog(tempPerson);
if (okClicked) {
mainApp.getPersonData().add(tempPerson);
}
}
/**
* Called when the user clicks the edit button. Opens a dialog to edit
* details for the selected person.
*/
@FXML
private void handleEditPerson() {
Person selectedPerson = personTable.getSelectionModel().getSelectedItem();
if (selectedPerson != null) {
boolean okClicked = mainApp.showPersonEditDialog(selectedPerson);
if (okClicked) {
showPersonDetails(selectedPerson);
}
} else {
// Nada seleciondo.
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Editar");
alert.setHeaderText(null);
alert.setContentText("Selecione uma pessoa por favor!");
alert.showAndWait();
}
}
}
`