Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: unable to add elements in jlist

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default unable to add elements in jlist

    UNable to add elements in jlist
    in constructor
    getting jlist blank
    following is my code :
     private Server ser=null;
        Thread my=null;
        DefaultListModel clients= new DefaultListModel();
     
        public UIServer(Server ser) {
            initComponents();
            this.ser=ser;
            setVisible(true);
           clients = new DefaultListModel();
                for(int i=0;i<=ser.clientsNames.length-1;i++)
                    {
     
                        clients.addElement(ser.clientsNames[i]);
                    }
                lstClient = new JList(clients);
                lstClient.setModel(clients);
                my= new Thread(this);
            //my.start();
        }

    I debugged and im getting values in list model and im using netbeans IDE


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: unable to add elements in jlist

    Please make a small complete program that compiles, executes and shows the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: unable to add elements in jlist

    class UIServer extends JFrame{
    private Server ser=null;
        Thread my=null;
        DefaultListModel clients= new DefaultListModel();
     
        public UIServer(Server ser) {
            initComponents();
            this.ser=ser;
            setVisible(true);
           clients = new DefaultListModel();
                for(int i=0;i<=ser.clientsNames.length-1;i++)
                    {
     
                        clients.addElement(ser.clientsNames[i]);
                    }
                lstClient = new JList(clients);
                lstClient.setModel(clients);
                add(lstClient);
                setvisible(true);
        }
    }
    class Server{
    public String clientsNames[]={"02","05","10","11","24","28","29","37","43","86"};
    public Server(){UIServer o = new UIServer(this);}
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: unable to add elements in jlist

    The posted code will not compile without import statements for the classes that are used.
    There is no main() method needed to execute the class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Unable to add JPanel to JScrollPane
    By nenay in forum AWT / Java Swing
    Replies: 8
    Last Post: February 25th, 2012, 03:10 PM
  2. need help understanding how to add to jlist
    By freakybeavis in forum AWT / Java Swing
    Replies: 1
    Last Post: February 5th, 2012, 04:23 PM
  3. unable to add my array(Words[]) to PriorityQueue
    By Harini Rao in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 10th, 2012, 07:08 AM
  4. Java App - Add, Delete, Reorder elements of the buttons
    By alibm in forum AWT / Java Swing
    Replies: 5
    Last Post: March 7th, 2011, 08:46 AM
  5. How to delete and add elements to an array dynamically?
    By k_w_r2007 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 21st, 2009, 11:31 AM