javaFX listview 里面的按钮点击事件
javaFX listview 里面的单元格是自定义的 为啥按钮触发不了点击事件啊,也就是button.setOnAction 里面点击事件为啥触发不了,(PS:列表的选择事件貌似也触发不了)
,求大神们指点下 试了一早上还是不行
package im.listcell;import im.base.BaseEntity;
import im.entity.UserEntity;
import im.window.ChatWindow;
import im.window.PersonMessageDetailWindow;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.ListCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import java.io.IOException;
/**
* 用户列表样式
*/
public class SearchUserCell extends ListCell<UserEntity>{
private HBox content;
private Text name;
private Text signature;
@Override
protected void updateItem(UserEntity item, boolean empty) {
// boolean f = getStylesheets().add(this.getClass().getResource("/Css/index.css").toExternalForm());
if(item!= null &&!empty){
VBox vBox = new VBox();
name = new Text(item.getNickname());
signature = new Text(item.getSignature());
vBox.getChildren().add(name);
vBox.getChildren().add(signature);
vBox.setPrefWidth(getScene().getWidth()/1.8);
//Hyperlink hyperlink = new Hyperlink("查看资料");
Button button = new Button("查看资料");
Hyperlink hyperlink1 = new Hyperlink("添加联系人");
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,button,hyperlink1);
content.setSpacing(5);
content.setMouseTransparent(false);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("点击");
PersonMessageDetailWindow personMessageDetailWindow = new PersonMessageDetailWindow();
personMessageDetailWindow.show();
}
});
setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
System.out.println("选中事件:"+getIndex());
if(event.getClickCount()==2){
System.out.println("点击2次");
try {
new ChatWindow().show();
} catch (IOException e) {
e.printStackTrace();
}
}else if(event.getClickCount()==1){
System.out.println("点击1次1");
}
}
});
setGraphic(content);
}else{
setGraphic(null);
}
}
}
以上是 javaFX listview 里面的按钮点击事件 的全部内容, 来源链接: utcz.com/p/944320.html