0

我在 JavaFX 中使用可编辑的 ComboBox。我连接了事件处理程序:

ComboBox cb = new ComboBox ();
cb.getEditor().setOnKeyTyped( ... );

如果我从键盘打字,这很好用。但是,如果我想检测这样的文本更改事件怎么办:

cb.getEditor().setText(val);

事件处理程序不会触发。我找不到任何方法来做到这一点。你有什么提示吗?...谢谢。

4

2 回答 2

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);
    }
});
于 2013-07-28T02:55:07.270 回答
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();
    }
}
于 2016-03-04T14:17:10.833 回答