我有一个TableColumn<Foo,String> fieldColumn=new TableColumn("field");
fieldColumn.setCellValueFactory(data->data.getValue().getFieldProperty());
tableView.add(fieldColumn);
,我创建的列是这样的:
tableView
现在我要销毁我的foos
,但我想继续使用所有foos
。这就是为什么我要解开<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
console.log( "ready!" );
if (!$.flash.hasVersion('9')) { //error
//has Flash
console.log( "flash installed!" );
...
&#39;表/列的属性。怎么做?
答案 0 :(得分:1)
如果删除TableColumn
,则在下一个布局过程中将删除侦听器。这样您就可以通过清除列并调用TableView
来删除layout()
添加的侦听器:
Item
类允许获取属性的侦听器数量
public class Item {
private final Set<Object> listeners = new HashSet<>();
public Item(String value) {
this.value.set(value);
}
private final StringProperty value = new SimpleStringProperty() {
@Override
public void removeListener(ChangeListener<? super String> listener) {
super.removeListener(listener);
listeners.remove(listener);
}
@Override
public void addListener(ChangeListener<? super String> listener) {
super.addListener(listener);
listeners.add(listener);
}
@Override
public void removeListener(InvalidationListener listener) {
super.removeListener(listener);
listeners.remove(listener);
}
@Override
public void addListener(InvalidationListener listener) {
super.addListener(listener);
listeners.add(listener);
}
};
public final StringProperty valueProperty() {
return this.value;
}
public int getListenerCount() {
return listeners.size();
}
}
文字Application
private void printListenerCount(String message) {
System.out.println(message + tableView.getItems().stream().mapToInt(Item::getListenerCount).sum());
}
private TableView<Item> tableView;
@Override
public void start(Stage primaryStage) {
tableView = new TableView<>();
tableView.getItems().addAll(new Item("a"), new Item("b"), new Item("c"));
TableColumn<Item, String> column = new TableColumn<>();
column.setCellValueFactory(cd -> cd.getValue().valueProperty());
tableView.getColumns().add(column);
Button btn = new Button("print listener count");
btn.setOnAction((ActionEvent event) -> {
printListenerCount("listeners: ");
});
Button btn2 = new Button("clear columns");
btn2.setOnAction(evt -> {
tableView.getColumns().clear();
// do layout to remove the listeners added for the columns
tableView.layout();
printListenerCount("after clear columns: ");
});
Scene scene = new Scene(new VBox(tableView, btn, btn2));
primaryStage.setScene(scene);
primaryStage.show();
}
按print listener count
然后按clear columns
按钮将产生以下输出:
listeners: 3
after clear columns: 0