我的uitableView中有这个自定义的Cell Factory。滚动时,该列非常慢。出现这种情况的任何原因以及我该如何改进。lastTradeColumn.setCellFactory( new Callback<TableColumn<Stock, Price>,TableCell<Stock, Price>>(){ @Override public TableCell<Stock, Price> call( TableColumn<Stock, Price> p ) { TableCell<Stock, Price> cell = new TableCell<Stock, Price>() { @Override public void updateItem(Price price, boolean empty) { super.updateItem(price, empty); if (price != null) { VBox vbox = new VBox(5); vbox.getChildren().add(new Label("£"+price.toString())); if( price.getOldPrice() > price.getNewPrice()) { vbox.setStyle("-fx-background-color:#EA2A15;"); } else if( price.getOldPrice() < price.getNewPrice()) { vbox.setStyle("-fx-background-color:#9CF311;"); } setGraphic( vbox ); } } }; return cell; }}); 最佳答案 您应该首先做的两件事是:1)而不是调用setStyle(...),而是调用getStyleClass()。add(...),然后使用外部CSS文件定义样式类。在运行时解析CSS很慢,因此请避免显示。2)重用VBox和Label,而不是每次调用updateItem时都重新创建它。通过将VBox和Label移动到updateItem方法的外部来做到这一点(但将其保留在新的TableCell ()大括号内)。但是....再加上2),我怀疑您是否需要VBox或Label。只需在单元格本身上设置样式类,然后使用setText(...)在单元格上设置文本。-乔纳森关于java - TableView中具有自定义CellFactory的Javafx 2.0慢列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8466215/
10-11 22:11
查看更多