JavaFX的同一个HBox下拖动下拉条左侧按钮乱跳动的问题?
大神们,我现在有个这样的按钮列,如图:
然后多条数据的话右边会有个下拉条,如图:
但是现在就是拉动右边的下拉条,左边的按钮就会乱跳动乱掉,如图:
然后排查了下原因是因为每拉动一次下拉条的时候会调用一个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);
}
}
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。