我有可编辑的组合框。
tf_name.getEditor().setOnKeyReleased(event -> {
tf_name.hide();
String name= tf_name.getEditor().getText().trim();
tf_name.getSelectionModel().clearSelection();
tf_name.getEditor().setText(name);
tf_name.setItems(Customer.getNameCompanyList(name));
int size=Customer.getNameCompanyList(name).size();
if (size>10) {size=10;
if (size==0) size=0;
}
tf_name.setVisibleRowCount(size);
if (size!=0)
tf_name.show();
tf_name.getEditor().end();
/*tv_info1.setItems(Info2.getInfo2NameDog(name));*/} );
tf_name.setOnAction( e->{
{
Customer customer=Customer.getCustomer(Customer.find_id_cust_Name(tf_name.getValue()));
tf_phone.setText(customer.getPhone());
cb_cust_district.setValue(customer.getDistrict());
cb_city_type.setValue(customer.getCity_type());
tf_city_name.setText(customer.getCity_name());
tf_street.setText(customer.getStreet());
tf_house.setText(String.valueOf(customer.getHouse()));
tf_housing.setText(customer.getHousing());
tf_flat.setText(String.valueOf(customer.getFlat()));
tf_code.setText(String.valueOf(customer.getCode()));
tf_oplata_nomer.setText(String.valueOf(customer.getNomer_oplat()));
}
});
当我从组合框中选择项目时,我需要做smth,而不是当我输入组合框或其他时。那么我需要什么动作事件,而不是setOnAction?
答案 0 :(得分:0)
您可以将更改侦听器添加到combobox的selectionModel的selectedItemProperty,如下面的演示代码:
ObservableList<String> options = FXCollections.observableArrayList();
options.addAll("hello", "hi", "bye", "morning");
ComboBox<String> myComboBox = new ComboBox<String>();
myComboBox.setItems(options);
myComboBox.getSelectionModel().selectedItemProperty().addListener( (Observable, oldValue, newValue) ->
System.out.println(newValue)
);
答案 1 :(得分:0)
在隐藏ComboBoxBase
弹出/显示之后调用。这意味着用户单击了某个项目或在视图外部单击。
combo.addEventHandler(ComboBoxBase.ON_HIDDEN, new EventHandler<Event>() {
@Override
public void handle(Event event) {
EditingUnitCell.this.commitEdit(combo.getSelectionModel().getSelectedIndex());
}
});