I'm learning API JavaFX for an application I'm working on at the moment and I am trying to use the CheckComboBox
from ControlsFX.
I've made a test in order to resolve a problem about items display refresh when I add items in the ObservableList
which populates the CheckComboBox
.
import org.controlsfx.control.CheckComboBox;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
public class Testin extends Application {
private Stage main;
private FlowPane root;
private ObservableList<String> l;
public Testin(){
root = new FlowPane();
l = FXCollections.observableArrayList();
l.add("bla");
l.add("shablagoo");
l.add("tirelipimpon");
}
@Override
public void start(Stage primaryStage) {
main = primaryStage;
CheckComboBox<String> test = new CheckComboBox<>();
test.getItems().addAll(l);
Button btn = new Button("test");
btn.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
l.add("ok");
System.out.println("ok");
}
});
root.getChildren().add(test);
root.getChildren().add(btn);
Scene scene = new Scene(root);
main.setScene(scene);
main.show();
}
public static void main(String[] args) {
launch(args);
}
}
Like a classic ComboBox
, when an item is added to the list, it would refresh itself automatically but it's not the case.
Do I have to create a ListChangeListener
which, at each modification report this on the displayed ComboBox
list, or is my code wrong ?
Additional information: I also try this test with a ComboBox
, replacing the CheckComboBox
and that runs well.