在另一个组合框(JavaFX)中选择项后动态更新组合框

在另一个组合框(JavaFX)中选择项后动态更新组合框,javafx,combobox,java-8,fxml,Javafx,Combobox,Java 8,Fxml,我有一个JavaFX表单,其中有两个组合框,分别以15分钟的增量填充开始和结束时间。我试图让“结束时间”组合框在用户选择开始时间时动态地重新填充选项,这样,如果用户已经选择了仍在开始时间之后的结束时间,则用户就不可能在开始时间之前选择结束时间,同时保留用户的选择 在测试代码是否正常工作时,我能够正确地填充这两个框并正确地保留用户的选择,但是,当用户选择新的开始时间时,我无法正确地触发事件。如果我使用onMouseClicked,它会在您单击组合框时触发事件,而不是在您进行选择时,如果使用onMo

我有一个JavaFX表单,其中有两个组合框,分别以15分钟的增量填充开始和结束时间。我试图让“结束时间”组合框在用户选择开始时间时动态地重新填充选项,这样,如果用户已经选择了仍在开始时间之后的结束时间,则用户就不可能在开始时间之前选择结束时间,同时保留用户的选择

在测试代码是否正常工作时,我能够正确地填充这两个框并正确地保留用户的选择,但是,当用户选择新的开始时间时,我无法正确地触发事件。如果我使用onMouseClicked,它会在您单击组合框时触发事件,而不是在您进行选择时,如果使用onMouseExit事件,它会起作用,但会在一个恼人的延迟之后

当组合框中的某个项目被选中时,我如何使其正确触发

FXML


我确信我遗漏了一些明显而简单的东西,但我似乎看不到。如果我错过了另一个问题,我为重复的问题道歉,但我在这里和其他网站上浏览了几篇文章,但没有弄清楚。如果您能提供任何帮助,我们将不胜感激。

也许您需要的是行动

// --- On Action
/**
 * The ComboBox action, which is invoked whenever the ComboBox
 * {@link #valueProperty() value} property is changed. This
 * may be due to the value property being programmatically changed, when the
 * user selects an item in a popup list or dialog, or, in the case of
 * {@link #editableProperty() editable} ComboBoxes, it may be when the user
 * provides their own input (be that via a {@link TextField} or some other
 * input mechanism.
 */
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() { return onAction; }
/--On Action
/**
*ComboBox操作,每当ComboBox
*{@link#valueProperty()value}属性已更改。这
*可能是由于以编程方式更改了value属性,当
*用户在弹出列表或对话框中选择项目,或者
*{@link#editableProperty()editable}组合框,可能是当用户
*提供他们自己的输入(可以是通过{@link TextField}或其他方式
*输入机制。
*/
公共最终ObjectProperty onActionProperty(){return onAction;}

您应该将第二个
组合框的
项属性
绑定到一个绑定,该绑定基于第一个
组合框的
值属性
,提供一个
过滤器列表
。在将代码更改为用于操作后,它可以正常工作。正如我所说的,我知道我缺少了一些简单的东西。谢谢。
@FXML
private void handleSelectStart(MouseEvent event){
    //Get the currently selected Start time from Start ComboBox
    LocalTime time = LocalTime.parse(cbStart.getValue(), timeDTF);

    //Store the current Selected End time for later comparison
    String currentEnd = cbEnd.getSelectionModel().getSelectedItem();

    //Clear out existing options from End Combo Box ObservableList
    availEndTimes.clear();

    do{
        availEndTimes.add(time.format(timeDTF));
        time = time.plusMinutes(15);
    } while(!time.equals(LocalTime.of(17, 15)));

    availEndTimes.remove(0);

    if(availEndTimes.contains(currentEnd)){
       cbEnd.setItems(availEndTimes);
       cbEnd.getSelectionModel().select(currentEnd);
       //setValidEndTimes();
    } else {
       cbEnd.setItems(availEndTimes);
       cbEnd.getSelectionModel().select(availEndTimes.get(0));
    }
}
// --- On Action
/**
 * The ComboBox action, which is invoked whenever the ComboBox
 * {@link #valueProperty() value} property is changed. This
 * may be due to the value property being programmatically changed, when the
 * user selects an item in a popup list or dialog, or, in the case of
 * {@link #editableProperty() editable} ComboBoxes, it may be when the user
 * provides their own input (be that via a {@link TextField} or some other
 * input mechanism.
 */
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() { return onAction; }