0

JavaFX で編集可能な ComboBox を使用しています。イベントハンドラーを接続しました:

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

キーボードから入力している場合、これは正常に機能します。しかし、次のようなテキスト変更でイベントを検出したい場合はどうすればよいでしょうか:

cb.getEditor().setText(val);

イベント ハンドラは起動しません。それを行う方法が見つかりませんでした。ヒントはありますか?... ありがとうございます。

4

2 に答える 2

2

Track the textProperty instead:

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 に答える