问题描述
我正在开发项目 Swing 应用程序,我想验证我的 GUI 中的 jTextFields.我找到了我添加到我的项目中的 ValidationAPI.jar,但它的文档真的很糟糕.我在 group.validateAll() 中有错误;打电话,我不知道如何解决.有没有人使用这个API?并知道如何修复它.
im working on project swing application and i want to validate jTextFields which i have in my GUI.I found ValidationAPI.jar which i added into my project, but there is really bad documentation for it.I have an error in group.validateAll(); call and i dont know how to fix it.Does anyone use this API? and know how to fix it.
final SwingValidationGroup group = SwingValidationGroup.create();
group.add(generationsTextField, StringValidators.REQUIRE_NON_EMPTY_STRING,
StringValidators.NO_WHITESPACE,
StringValidators.REQUIRE_VALID_INTEGER);
generationsTextField.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
checkValidation();
}
public void removeUpdate(DocumentEvent e) {
checkValidation();
}
public void changedUpdate(DocumentEvent e) {
checkValidation();
}
private void checkValidation() {
Problem validateAll = group.validateAll();
if (validateAll.isFatal()) {
startAlgorithm.setEnabled(false);
isValid = !validateAll.isFatal();
} else {
startAlgorithm.setEnabled(true);
isValid = !validateAll.isFatal();
}
}
});
当我调用 validateAll();
它给了我下面的错误 --
it gives me an error below --
线程AWT-EventQueue-0"中的异常java.lang.NoClassDefFoundError:org/openide/util/查找org.netbeans.validation.api.ui.swing.SwingComponentDecorationFactory.getDefault( SwingComponentDecorationFactory.java:154)在org.netbeans.validation.api.ui.swing.SwingValidationGroup.(SwingValidation Group.java:82)在org.netbeans.validation.api.ui.swing.SwingValidationGroup.create(SwingValidation Group.java:87)在 com.mendelu.ga_scp.gui.GUI.(GUI.java:43)
.
推荐答案
我猜你在 Netbeans 中创建了一个普通的 Java 应用程序项目.为了验证,您使用了 ValidationAPI.jar 而没有任何进一步的 api.ValidationAPI.jar 是 Netbeans 应用程序框架
(NAF) 的一部分,这是一组非常复杂的库,用于编写标准的桌面"应用程序.ValidationAPI 依赖于来自 NAF 的其他包(jar).你至少会错过 org.openide.util.Lookup 类.
I guess you created a plain Java application project in Netbeans. For validation you took the ValidationAPI.jar without any further apis. ValidationAPI.jar is part of the Netbeans Application Framework
(NAF), a quite complex set of libraries to write standard "desktop" applications. The ValidationAPI depends on other packages (jars) from the NAF. And you miss at least the org.openide.util.Lookup class.
您可以手动解决依赖项(将所有 jar 文件或使用 maven 放入您的项目中)或从头开始创建 NAF 程序.
You may solve the dependencies manually (put into your project all jars or with maven) or create a NAF programm from scratch.
另一种选择是使用与框架无关的验证库,例如 OVal.
Another option is to use a framework agnostic validation library such as OVal.
这篇关于ValidationAPI java swing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!