実際は、入力するコントロールによって異なります。
シーングラフに多くのノードを追加することはコストがかかるため、遅くなります(例えば、Text
オブジェクトを任意のコンテナに配置するなど)。
ListViewのように、もともと膨大な量のデータを表示するように設計されたコントロールの使用をお勧めします。
この例では、ListView
の更新中でも、Button
が応答します。
Main.java
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
HBox root = new HBox();
Scene scene = new Scene(root, 700, 400, Color.WHITE);
TableView<Person> personsTable = new TableView<Person>();
TableColumn<Person, String> nameCol = new TableColumn<Person, String>("Name");
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
personsTable.getColumns().add(nameCol);
ObservableList<Person> persons = FXCollections.observableArrayList();
Thread th = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 100000; i++) {
Person person = new Person();
person.setName("Name" + i);
person.setAddress("Address" + i);
person.setCountry("Country" + i);
person.setCourse("Course" + i);
persons.add(person);
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}) ;
th.start();
personsTable.setItems(persons);
Button b = new Button();
b.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("I am printing independently of Person update!");
}
});
root.getChildren().addAll(personsTable, b);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Person.java
public class Person {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
private String name;
private String address;
private String country;
private String course;
}
ユーザーjewelseaはlggingに本当に良いexampleを行いました。ちょっとした仕立てで、あなたの問題を解決することができます。