标签:data mtab upd center 改进 this and created mod
大神们,我如今有个这种button列。如图:
然后多条数据的话右边会有个下拉条。如图:
可是如今就是拉动右边的下拉条。左边的button就会乱跳动乱掉。如图:
然后排查了下原因是由于每拉动一次下拉条的时候会调用一个updateItem()的方法。怎么样让这个下拉条拖动
的时候仅仅回调一次这个updateItem()方法? 或者有其它办法改进这样的BUG吗?急求!!
!。。!!
部分代码例如以下:
public class AllRoomOperateButtonTableCell<S, T> extends TableCell<S, T> {
private final HBox mHbox;
private final Button mViewBn;
private final Button mViewPicBn;
private ObservableValue<T> ov;
private final ObservableList<RoomOperateRecordInfo> mTransList;
private RoomOperateRecordInfo mTransInfo;
private final TableView mTableView;
public AllRoomOperateButtonTableCell(ObservableList<RoomOperateRecordInfo> transList,TableView tableView) {
this.mTransList = transList;
this.mTransInfo = null;
this.mTableView = tableView;
this.mHbox = new HBox();
this.mHbox.setSpacing(5);
this.mHbox.setAlignment(Pos.CENTER);
this.mViewBn = ButtonBuilder.create()
.text("查看")
.prefWidth(60)
.prefHeight(30)
.build();
this.mViewBn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
synchronized (mTransList) {
mTableView.getSelectionModel().select(getIndex());
mTransInfo = mTransList.get(getIndex());
if (mTransInfo.getStatus() == CHECK_TRANS_DONE + 10 || mTransInfo.getStatus() == CHECK_TRANS_CANCELLED + 10 || mTransInfo.getStatus() == CHECK_TRANS_SYSTEMCANCELLED + 10) {
CheckingRoomTransInfo checkInfo = new CheckingRoomTransInfo(mTransInfo.getTransId(), mTransInfo.getSubmitTime(), mTransInfo.getRoomNo(), mTransInfo.getCreatedByENo(), mTransInfo.getReadFlag(), mTransInfo.getStatus(), mTransInfo.getProcessTime(),
mTransInfo.getComments(), mTransInfo.getProcessENo());
for(int i=0;i<mTransInfo.getmMinibarInfosList().size();i++){
checkInfo.addmMinibarInfosList(mTransInfo.getmMinibarInfosList().get(i));
}
showCheckTransDetail(checkInfo, null);
}else if (mTransInfo.getStatus() == CLEAN_TRANS_UNHANDLED || mTransInfo.getStatus() == CLEAN_TRANS_UNINSPECTED || mTransInfo.getStatus() == CLEAN_TRANS_INSPECTED || mTransInfo.getStatus() == CLEAN_TRANS_UNPASSED ||mTransInfo.getStatus()
== CLEAN_TRANS_DELAYED ||mTransInfo.getStatus() == CLEAN_TRANS_CANCELLED || mTransInfo.getStatus() == CLEAN_TRANS_TIMEOUT) {
CleanTransInfo cleanInfo = new CleanTransInfo(mTransInfo.getTransId(), mTransInfo.getSubmitTime(), mTransInfo.getRoomNo(), mTransInfo.getCreatedByENo(), mTransInfo.getReadFlag(), mTransInfo.getStatus(), 2, mTransInfo.getProcessTime(),
mTransInfo.getComments(), mTransInfo.getProcessENo());
showCleanTransDetail(cleanInfo, null);
}
mTableView.requestFocus();
}
}
});
this.mViewPicBn = ButtonBuilder.create()
.text("看图")
.prefWidth(60)
.prefHeight(30)
.build();
this.mViewPicBn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
mTableView.getSelectionModel().select(getIndex());
mTransInfo = mTransList.get(getIndex());
showRelatedPicDetail(null,mTransInfo);
mTableView.requestFocus();
}
});
mHbox.getChildren().addAll(mViewBn);
setAlignment(Pos.CENTER);
setGraphic(mHbox);
}
@Override
public void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
setGraphic(mHbox);
ov = getTableColumn().getCellObservableValue(getIndex());
if (ov instanceof IntegerProperty) {
int status = ((IntegerProperty) ov).get();
if (status == CHECK_TRANS_DONE + 10 || status == CHECK_TRANS_CANCELLED + 10 || status == CHECK_TRANS_SYSTEMCANCELLED + 10
|| status == CLEAN_TRANS_INSPECTED || status == CLEAN_TRANS_CANCELLED || status == CLEAN_TRANS_TIMEOUT) {
mViewBn.setText("查看");
mViewBn.setStyle("-fx-base: olivedrab;");
}else if (status == CHECK_STATUS_CHECKOUT || status == CHECK_TRANS_UNHANDLED + 100 || status == CHECK_TRANS_DONE + 100 || status == CHECK_TRANS_CANCELLED + 100
|| status == CHECK_TRANS_SYSTEMCANCELLED + 100 || status == CLEAN_STATUS_CREATE || status == -CLEAN_TRANS_UNINSPECTED || status == -CLEAN_TRANS_INSPECTED
|| status ==-CLEAN_TRANS_UNPASSED ||status ==-CLEAN_TRANS_DELAYED || status == -CLEAN_TRANS_CANCELLED || status == -CLEAN_TRANS_TIMEOUT || status == NOTIFY_LOG) {
setGraphic(null);
return;
} else {
mViewBn.setText("处理");
mViewBn.setStyle("-fx-base: orange;");
}
}
if (mTransInfo == null) {
mTransInfo = mTransList.get(getIndex());
if (mTransInfo.IsChecking() != null && mTransInfo.IsChecking() != "" && mTransInfo.getRelatedPicList().size() > 0) {
mHbox.getChildren().add(0,mViewPicBn);
}
}
}
}
}
JavaFX的同一个HBox下拖动下拉条左側button乱跳动的问题?
标签:data mtab upd center 改进 this and created mod
原文地址:http://www.cnblogs.com/ljbguanli/p/7238902.html