javaFX listview 选中变色
javaFX listview 选中当前条目变色,之前已经选中的上一个条目恢复成白色 怎么操作。,
package im.listcell;import im.base.BaseEntity;
import im.entity.UserEntity;
import javafx.event.EventHandler;
import javafx.scene.control.ListCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
/**
* 用户列表样式
*/
public class UserlistCell extends ListCell<BaseEntity>{
private HBox content;
private Text name;
@Override
protected void updateItem(BaseEntity item, boolean empty) {
if(item!= null &&!empty){
VBox vBox = new VBox();
name = new Text(item.getName());
vBox.getChildren().add(name);
ImageView imageView = new ImageView();
Image image = new Image(item.getUrl());
Circle circle = new Circle();
circle.setCenterX(30);
circle.setCenterY(30);
circle.setRadius(60);
imageView.setFitWidth(30);
imageView.setFitHeight(30);
imageView.setImage(image);
imageView.setClip(circle);
content = new HBox(imageView,vBox);
content.setSpacing(10);
setGraphic(content);
setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if(event.getClickCount()==2){
System.out.println("点击2次");
//变色
setStyle("-fx-background-color: #72b9da");
}else if(event.getClickCount()==1){
System.out.println("点击1次");
}
}
});
}else{
setGraphic(null);
}
}
}
以上是 javaFX listview 选中变色 的全部内容, 来源链接: utcz.com/p/944284.html