javafx table列中增加按钮图片

阅读更多
//操作按钮列
operTableColumn.setCellFactory((col) -> {
	TableCell cell = new TableCell() {
		public HBox paddedButton = new HBox();
        Label delBtn = new Label("删除");
        Label editBtn = new Label("编辑");
        Label pwdBtn = new Label("密码修改");

        {
            paddedButton.getStylesheets().add("/com/redphase/ui/user/user.css");

            delBtn.getStyleClass().addAll("ob");
            ImageView delImageView = new ImageView(new Image("/com/redphase/ui/iconfont/del.png"));
            delImageView.setFitWidth(20);
            delImageView.setFitHeight(20);
            delBtn.setGraphic(delImageView);

            editBtn.getStyleClass().addAll("ob");
            ImageView editImageView = new ImageView(new Image("/com/redphase/ui/iconfont/edit.png"));
            editImageView.setFitWidth(20);
            editImageView.setFitHeight(20);
            editBtn.setGraphic(editImageView);

            pwdBtn.getStyleClass().addAll("ob");
            ImageView pwdImageView = new ImageView(new Image("/com/redphase/ui/iconfont/barrage_fill.png"));
            pwdImageView.setFitWidth(20);
            pwdImageView.setFitHeight(20);
            pwdBtn.setGraphic(pwdImageView);

            paddedButton.getChildren().addAll(editBtn, delBtn, pwdBtn);
        }
	@Override
    protected void updateItem(String item, boolean empty) {
        super.updateItem(item, empty);
        if (!empty) {
			paddedButton.setPadding(new Insets(3));
            delBtn.setOnMouseClicked((m) -> {
                log.debug("OperButtonCell...del");
                UserDto userDto = (UserDto) table.getSelectionModel().getSelectedItem();
                del(userDto.getId());
            });
            editBtn.setOnMouseClicked((m) -> {
                log.debug("OperButtonCell...edit");
                UserDto dto = (UserDto) table.getSelectionModel().getSelectedItem();
                idialog.openDialog("用户编辑", userEditView, 650.0, 450.0);
                showInfo(dto);
            });
            pwdBtn.setOnMouseClicked((m) -> {
                log.debug("OperButtonCell...pwdBtn");
                UserDto dto = (UserDto) table.getSelectionModel().getSelectedItem();
                idialog.openDialog("密码修改", userPwdView, 650.0, 450.0);
                idT.setText("" + dto.getId());
            });
            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            setGraphic(paddedButton);
        } else {
            setGraphic(null);
        }
    
	};
	return cell;
});

 

你可能感兴趣的:(javafx)