JavaFX FXML - 按钮是否有类似 OnEdit 的方法?
JavaFX FXML - Does Button have OnEdit Like Method?
我有一个扩展 Button
的 class,其中 String
是这样构建的,
text = button.getText();
但是,我需要在文本发生变化时始终更新文本,即监听器。 Button 是否有像 onEdit 这样的方法,我可以确保按钮的文本始终与变量文本相同?
使用按钮的文本注册监听器 属性:
button.textProperty().addListener((obs, oldText, newText) -> {
// do whatever you need with newText
});
我有一个扩展 Button
的 class,其中 String
是这样构建的,
text = button.getText();
但是,我需要在文本发生变化时始终更新文本,即监听器。 Button 是否有像 onEdit 这样的方法,我可以确保按钮的文本始终与变量文本相同?
使用按钮的文本注册监听器 属性:
button.textProperty().addListener((obs, oldText, newText) -> {
// do whatever you need with newText
});