【发布时间】:2017-03-13 13:31:55
【问题描述】:
我正在开发预订系统的界面。在一个窗口中,我需要获取预订的开始时间和所需预订的结束时间,以便检查数据库是否可用。 (只有 hh:mm 感兴趣,我在其他地方度过了一天)。 组合框如下所示:
//startTime HBox
HBox startTime = new HBox();
startTime.setSpacing(5);
final ComboBox startHours = new ComboBox(hours);
final ComboBox startMinutes = new ComboBox(minutes);
final Label colon = new Label(":");
startTime.getChildren().addAll(startHours,colon,startMinutes);
endTime 也是一样的(一个 HBox 有相同的组件只是改变了变量名
我希望我的 startTime 小时组合框自动禁用那些高于当前 endTime 组合框小时的项目,反之亦然,我希望禁用低于 startTime 小时组合框的 endTime 小时项目。 我尝试制作一个单元格工厂,但是如果我在编辑另一个组合框之前打开组合框,它就不起作用。
startHours.setCellFactory(
new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<String> call(ListView<String> param) {
final ListCell<String> cell = new ListCell<String>() {
@Override public void updateItem(String item,
boolean empty) {
super.updateItem(item, empty);
if (item!=null){
setText(item);
}
if ((endHours.getValue()!=null) && (endHours.getValue().toString().compareTo(item)<0)){
setDisable(true);
setStyle("-fx-background-color: #ffc0cb");
}
}
};
return cell;
}
});
【问题讨论】: