简体   繁体   中英

Cannot assign my DefaultListModel to my JList in Java NetBeans

I have a jList that was generated by NetBeans. I have declared a DefaultListModel but cannot link to up to the jList. My code is below and I have also tried using .setMethod.

        DefaultListModel modeljLstShoppingCartName;
        modeljLstShoppingCartName = new DefaultListModel();
        jLstShoppingCartName = new JList(modeljLstShoppingCartName);
        modeljLstShoppingCartName.addElement("Testing1");

The error I am receiving here is on the entire third line where it is saying:

incompatible types
  required: java.awt.List
  found:    javax.swing.JList

I have imported:

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.DefaultListModel;
import javax.swing.JList;

Any help would be great as I've spent a few hours at this but with no success.

Regarding:

incompatible types
  required: java.awt.List
  found:    javax.swing.JList

This could be little more than a careless mistake. I'm betting that you have declared your jLstShoppingCartName variable as a java.awt.List variable not a javax.swing.JList variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM