- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
使用JavaFX8,如果只有 ObjectProperty
的一个属性,如何能够收到通知?发生变化,但引用保持不变?
下面是使用 ObjectProperty<KeyStore>
的具体示例。 java.security.KeyStore
保存 key 和证书的列表。如果添加、更改或删除条目,我希望收到通知。
public abstract class EntityController {
protected ObjectProperty<KeyStore> trustStore = new SimpleObjectProperty<KeyStore>();
public EntityController() {
}
public KeyStore getTrustStore() {
return this.trustStore.getValue();
}
public void setTrustStore(KeyStore trustStore) {
this.trustStore.set(trustStore);
}
public ObjectProperty<KeyStore> trustStoreProperty() {
return this.trustStore;
}
}
public class CertificatesTabPresenter extends PKIPresenter implements Initializable {
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
this.getEntityController().trustStoreProperty().addListener((observableVal, oldTrustStore, newTrustStore) -> {
trustStoreChanged(oldTrustStore, newTrustStore);
});
}
@FXML
private void addTrustStore(MouseEvent e) {
File keyStoreFile = selectKeyStoreFile();
if (keyStoreFile != null) {
Optional<String> keyStoreType = selectKeyStoreType();
if(keyStoreType.isPresent()) {
Optional<char[]> password = insertPassword();
if(password.isPresent()) {
try {
KeyStore trustStore = KeyStore.getInstance(keyStoreType.get());
trustStore.load(null, null);
FileInputStream fis = new FileInputStream(keyStoreFile);
trustStore.load(fis, password.get());
//This causes the changeListener to be notified because the reference changed
this.getEntityController().setTrustStore(trustStore);
//The changeListener won't be notified, because only the KeyStore changes internally but the reference stays the same
trustStore.deleteEntry(trustStore.aliases().nextElement());
this.getEntityController().setTrustStore(trustStore);
//This also won't notify the changeListener
String a = this.getEntityController().getTrustStore().aliases().nextElement();
this.getEntityController().getTrustStore().deleteEntry(a);
} catch (KeyStoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NoSuchAlgorithmException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (CertificateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
//TODO: password was wrong -> show error message
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
}
}
相关代码是ObjectProperty
所在的位置s 值第一次被设置,然后一个元素被删除。仅当 ObjectProperty
时,changeListener 才会收到通知。 s 值已设置,但值更改时不设置。
我的问题是:如果 KeyStore
我怎样才能得到通知即使引用的对象没有改变也会更新?JavaFX中有内置的方法吗?
我的目的是显示 ListView
中包含的所有证书和 key 并更新ListView
每次在KeyStore
中添加或删除证书时从changeListener 中。也许我完全走错了路,我应该采取完全不同的做法?
其他信息:
this.getEntityController()
返回 EntityController
的实例它本身保存在 ObjectProperty<EntityController>
中.
最佳答案
我不知道处理此限制的更好方法,因此我所做的只是对修改后的对象执行 set() 操作,以便引用保持相同,但更改会传播。
关于java - 除非 ObjectProperty 的源发生更改,否则不会触发 ChangeListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41257439/
我有一个带有 NumberSpinner 的场景元素和 ComboBox元素,我想绑定(bind) minValue NumberSpinner的属性(property)valueProperty 为
我要绑定(bind) dp_date_add.valueProperty().bindBi Direction(model.forDateProperty()); 其中 forDateProperty
我有一个名为Tree的类 public class Tree { private Color c; public Color getColor() { retu
假设我有三个类: class A { val bProperty: ObjectProperty = SimpleObjectProperty(B(C("test"))) val cO
我的应用程序有一个包含多个 ObjectProperty 的对象字段。我正在尝试编写一个执行以下操作的辅助方法: 接受任何类型的 ObjectProperty作为参数 显示ChoiceDialog弹出
我的应用程序有一个包含多个 ObjectProperty 的对象字段。我正在尝试编写一个执行以下操作的辅助方法: 接受任何类型的 ObjectProperty作为参数 显示ChoiceDialog弹出
我刚开始学习kivy,我对ObjectProperty类的用法以及它如何将None作为参数感到非常困惑。有人可以解释一下吗?我在kivy教程中找到了它: class PongGame(Widget):
我正在创建一个 kivy 用户界面来显示由我编写为标准 python 对象的数据模型生成的值。本质上,我希望用户能够按下一个按钮,这将更改底层数据模型,并且此更改的结果将自动更新和显示。据我了解,这可
我正在使用 ScalaFX GUI 和 Akka 远程处理网络制作多人游戏客户端。当我的客户端收到游戏数据时,它会将其存储在 Model.gameData 中。我需要我的 GUI 来响应这个变量变化。
我正在使用 OWL API 和 Java (Eclipse) 开发一种算法。对于我的 ASSOCIATION 案例,我需要创建一个公理,其中 AGGREGATION 和 COMPOSITION 作为
我想了解 ObjectProperty 的工作原理,但仍然没有成功。我有以下 POJO: public class Article{ private LocalDateTime dateTim
我有一个包装 ObservableList 的属性。但我不知道如何初始化它。目前我正在这样做 ObjectProperty> property = new ChoiceBox().itemsPrope
我有这个人物 TableView :
我扩展了 SimpleObjectProperty创建自定义延迟加载实现(see here),LazyLoadingObjectProperty . 要将此通用实现用于 boolean 属性,我使用
在 W3 OWL 规范中,个体的属性分为两组:数据类型属性和对象属性。定义了对象属性(正如我发现的一篇文章所说的那样): "Object properties (owl:ObjectProperty)
ObjectPropertyBase 在 newValue == oldValue 时跳过值失效: /** * {@inheritDoc} */ @Override public void set
在RDF中,语句用S、P和O表示;在 OWL 中,owl:ObjectProperty 表示谓词逻辑。 (S) (P) (O) I like dog
我正在尝试创建一条指向属性中节点的线: ObjectProperty pointedToNode = new SimpleObjectProperty(); 我想要一条线像这样指向它: line.en
我正在尝试加载 ontology在 Protégé 中,但未按预期进行处理。最有问题的是所有对象和数据属性都显示为注释,而不是数据属性和对象属性。 我有一个对象属性kingdom: king
我研究了一些类及其声明,发现了一种新的封装方式,它使得访问实例变量的普通 getter/setter 方式看起来像野蛮行为...... 内部javafx.scene.Scene搜索相机,javafx.
我是一名优秀的程序员,十分优秀!