我在JavaFX中使用可编辑的ComboBox。我连接了事件处理程序:
ComboBox cb = new ComboBox ();
cb.getEditor().setOnKeyTyped( ... );
如果我从键盘输入,这可以正常工作。但是如果我想检测文本更改的事件如下:
cb.getEditor().setText(val);
事件处理程序不会触发。我找不到任何办法。你有任何提示吗?...谢谢。
答案 0 :(得分:2)
跟踪textProperty:
cb.getEditor().textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
System.out.println(oldValue + " --> " + newValue);
}
});
答案 1 :(得分:0)
private void EditeActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
String btntitle=this.Edite.getText();
if(btntitle.compareToIgnoreCase("edite")==0) {
int index=this.Table.getSelectedRow();
this.txtProductId.setText(""+tm.getValueAt(index, 0));
this.txtLastName.setText(""+tm.getValueAt(index, 1));
this.txtFirstName.setText(""+tm.getValueAt(index, 2));
this.txtTel.setText(""+tm.getValueAt(index, 3));
this.jComboBoxGender.setSelectedIndex(tm.getValueAt(index, 4));
this.Edite.setText("update");
}
if(btntitle.compareToIgnoreCase("update")==0) {
int index=Table.getSelectedRow();
int productid=Integer.parseInt(txtProductId.getText());
String lastname=txtLastName.getText();
String firstname=txtFirstName.getText();
String sex=txtTel.getText();
tm.setValueAt(productid,index, 0);
tm.setValueAt(lastname,index, 1);
tm.setValueAt(firstname,index, 2);
tm.setValueAt(sex,index, 3);
cleardata();
}
}