swing - NetBeans GUI 生成器找不到 SwingX 类

标签 swing noclassdeffounderror classnotfoundexception swingx matisse

我被投入到一个现有的软件开发项目中,该项目在 NetBeans Java 项目中使用 Maven

我已将源代码从受祝福的 git 存储库中提取到新安装的 NetBeans 8 中。如果我构建并运行它,它就会运行。 :-)

我必须编辑使用 NetBeans GUI 生成器创建的程序的 GUI。如果我尝试打开 GUI 编辑器,它总是将一些 extends JXPanel 的组件标记为 invalid,因为以下错误:

java.lang.NoClassDefFoundError:org/jdesktop/swingx/JXPanel ... 由 java.lang.ClassNotFoundException: org.jdesktop.swingx.JXPanel 引起

我根本不明白 - 文件 swingx-1.6.jarswingx-beaninfo-1.6.jar 在项目的依赖项部分(没有“!”),我已将它们添加到 Libraries Manager,并将它们添加到 Palette。程序运行了,但是为什么,为什么,为什么 NetBeans GUI 编辑器找不到类?

我做错了什么?

以下是 pom.xml 的摘录:

<dependency>
    <groupId>org.jdesktop</groupId>
    <artifactId>swingx</artifactId>
    <version>1.6</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/swingx-1.6.jar</systemPath>
</dependency>
<dependency>
    <groupId>org.jdesktop</groupId>
    <artifactId>swingx.beaninfo</artifactId>
    <scope>system</scope>
    <version>1.6</version>
    <systemPath>${basedir}/lib/swingx-beaninfo-1.6.jar</systemPath>
</dependency>

最佳答案

我建议您使用中央 Maven 存储库中的 swingx 而不是本地副本 - 我怀疑存在错误或 GUI 编辑器无法解析 ${basedir}。这是我的设置,效果很好:

<dependencies>
    <dependency>
        <groupId>org.swinglabs.swingx</groupId>
        <artifactId>swingx-all</artifactId>
        <version>1.6.5</version>
    </dependency>
</dependencies>

和对应的Java类:

public class NewJFrame extends javax.swing.JFrame {

/**
 * Creates new form NewJFrame
 */
public NewJFrame() {
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    jXPanel1 = new org.jdesktop.swingx.JXPanel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jXPanel1.setBackground(new java.awt.Color(153, 204, 255));

    javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
    jXPanel1.setLayout(jXPanel1Layout);
    jXPanel1Layout.setHorizontalGroup(
        jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 259, Short.MAX_VALUE)
    );
    jXPanel1Layout.setVerticalGroup(
        jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 171, Short.MAX_VALUE)
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(131, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(118, Short.MAX_VALUE))
    );

    pack();
}// </editor-fold>//GEN-END:initComponents

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new NewJFrame().setVisible(true);
        }
    });
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private org.jdesktop.swingx.JXPanel jXPanel1;
// End of variables declaration//GEN-END:variables

关于swing - NetBeans GUI 生成器找不到 SwingX 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26917893/

相关文章:

android - 使用 MapView 抛出 ClassNotFoundException

Java Eclipse Java 构建路径添加项目 ClassNotFoundException

java.lang.ClassNotFoundException : org. apache.james.mime4j.message.Message

java - 从数据库填充 DefaultMutableTreeNode

java - 使用外部库将 Jar 转换为 exe

java - 如何使用 DropBox 和 Eclipse for Java 避免找不到主类和类定义错误

枚举上的 Java NoClassDefFoundError 错误

java - 如何实现InternalFrameListener?

Java Swing 面板大小

reference - 如何在gradle中导出可执行jar,并且这个jar可以运行,因为它包含引用库