JList.getModel() ClassCastException

前端 未结 4 734
悲哀的现实
悲哀的现实 2020-12-16 21:56

When I call JList.getModel() and cast it to DefaultListModel it gives me this exception.

Exception in t         


        
4条回答
  •  -上瘾入骨i
    2020-12-16 22:19

    I experienced this issue. I found this simple workaround:

    //----instantiation----
    
        JList mList = new JList();
        mList.setModel(new DefaultListModel());
    
        /*---- do whatever you want---- */
    
        //Retain it wherever you want with
        DefaultListModel model = (DefaultListModel)mList.getModel();
    

提交回复
热议问题