首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GroupLayout上的NotSerializableException,但未使用GroupLayout

GroupLayout上的NotSerializableException,但未使用GroupLayout
EN

Stack Overflow用户
提问于 2018-11-26 04:35:32
回答 1查看 69关注 0票数 0

我正在编写一段代码,其中我需要扩展JPanel,然后序列化它的结果。然而,在尝试序列化它时,我得到了这个错误:

代码语言:javascript
复制
java.io.NotSerializableException: javax.swing.GroupLayout

我尝试序列化的对象的代码如下:

代码语言:javascript
复制
public class NewJPanel extends javax.swing.JPanel
{

    /**
     * Creates new form NewJPanel
     */
    public NewJPanel()
    {
        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">                          
    private void initComponents()
    {
    }// </editor-fold>                        


    // Variables declaration - do not modify                     
    // End of variables declaration                   
}

尝试序列化一个普通的、非扩展的JPanel是可行的,但是扩展的a不行。正如您所看到的,没有使用GroupLayout,面板默认使用FlowLayout。即使显式设置它也不能阻止这一点。谁能告诉我为什么会发生这种情况,以及我可以如何修复或解决此问题?

EN

回答 1

Stack Overflow用户

发布于 2018-11-27 02:11:49

原来,当我将JPannel的布局管理器放到JFrame中时,Netbeans上的JPannel表单构建器偷偷地将其设置为GroupLayout,而不是将其保留为我在JPannel的代码中指定的布局。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53471688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档