开发者

.txt in combo box

开发者 https://www.devze.com 2023-03-16 19:56 出处:网络
I am new in the world of programming and am completing a Java programming assignment.In my assignment I am having a problem trying to display a list of .txt files in a combo box. Can some body help me

I am new in the world of programming and am completing a Java programming assignment. In my assignment I am having a problem trying to display a list of .txt files in a combo box. Can some body help me please? Here is the code that I am trying to use.

  DefaultListModel listModel = new DefaultListModel();
  Object list1Selected = list1.getSelectedItem();
  String selected = list1Selected.toString();
  System.out.println(selected);
  String files;

  File folder = new File("/Assignment_Datex/new_destination/msgsend0.txt",
           selected);
  File[] listOfFiles = folder.listFiles();
  for (int i = 0; i < listOfFiles.length; i++) {
     if (listOfFiles[i].isFile()) {
        files = listOfFiles[i].getName();
        listModel.addElement(files);
    开发者_C百科 }
     list.setModel(null);
  }


Why do you call list.setModel(null); into the loop? Remove this line and call list.setModel(listModel); after the loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号