Java 如何从可编辑组合框上更改的文本中获取事件?
我在JavaFX中使用可编辑的组合框。我已连接事件处理程序:Java 如何从可编辑组合框上更改的文本中获取事件?,java,events,javafx,Java,Events,Javafx,我在JavaFX中使用可编辑的组合框。我已连接事件处理程序: ComboBox cb = new ComboBox (); cb.getEditor().setOnKeyTyped( ... ); 如果我用键盘打字,这个效果很好。但如果我想检测文本更改事件,该怎么办 cb.getEditor().setText(val); 事件处理程序不会启动。我找不到任何方法来做那件事。你有什么提示吗?。。。谢谢。请改为跟踪textProperty: cb.getEditor().textProperty
ComboBox cb = new ComboBox ();
cb.getEditor().setOnKeyTyped( ... );
如果我用键盘打字,这个效果很好。但如果我想检测文本更改事件,该怎么办
cb.getEditor().setText(val);
事件处理程序不会启动。我找不到任何方法来做那件事。你有什么提示吗?。。。谢谢。请改为跟踪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);
}
});
cb.getEditor().textProperty().addListener(新的ChangeListener()){
@凌驾
你能不能把你的答案格式化得更好,并解释一下你做了什么?
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();
}
}