在ControlsFX CheckComboBox显示刷新问题 [英] Refresh issue on ControlsFX CheckComboBox display
问题描述
我正在为我正在处理的应用程序学习API JavaFX,我试图使用ControlsFX的 CheckComboBox
。
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.
我已经做了一个测试,以解决有关项目显示刷新的问题,当我在 ObservableList
中添加项目时填充 CheckComboBox
。
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);
}
}
像一个经典的 ComboBox
,当一个项目被添加到列表,它会自动刷新本身,但事实并非如此。
我必须创建一个 ListChangeListener
,在每个修改报告这在显示的 ComboBox
列表,或者我的代码错了吗?
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 ?
其他信息:我还尝试使用 ComboBox
c $ c> CheckComboBox 并且运行良好。
Additional information: I also try this test with a ComboBox
, replacing the CheckComboBox
and that runs well.
推荐答案
test.getItems().addAll(someList);
将 someList
的所有元素复制到组合框的项目列表。显然, someList
的后续更改对组合框不会有任何影响。
copies all the elements of someList
to the combo box's items list. Clearly, subsequent changes to someList
won't have any effect on the combo box.
您要替换
test.getItems().addAll(l);
test.setItems(l);
p>
or you want to replace
l.add("ok");
test.getItems().add("ok");
这篇关于在ControlsFX CheckComboBox显示刷新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!