Jlist不刷新

时间:2015-05-04 15:57:09

标签: java swing jpanel custom-controls jlist

我有一个主jFrame,并在框架中添加了自定义jPanel。使用cardLayout我根据用户点击/输入的内容在面板之间切换。

用户可以在某一时刻搜索配方,并将结果添加到JScrollPane中的jList。然后显示单独的面板,应显示结果。问题是结果永远不会显示。我觉得这很令人耳目一新,但我不熟悉挥杆。

以下是执行此操作的实际方法的代码:

 public ArrayList<Menu> menuListResults(SearchParameters p) throws ClassNotFoundException, SQLException {
    DefaultListModel model = new DefaultListModel();

    ArrayList<Menu> searchResults = new ArrayList();

    // Test Menu Object
    LocalDate menu_date = LocalDate.now();
    Menu m1 = new Menu(12463, "", "HOTEL EASTMAN", "BREAKFAST", "COMMERCIAL", "HOT SPRINGS, AR",
            "CARD; 4.75X7.5", "EASTER", "", "1900-2822", "" , "", menu_date, "Hotel Eastman", "", "",
            "", "UNDER REVIEW", 2, 67);
    searchResults.add(m1);      

    if (searchResults == null || searchResults.isEmpty()) {
        JOptionPane.showMessageDialog(null, "No menus returned from that search!", "Error", JOptionPane.ERROR_MESSAGE);
    }
    else {
        for (Menu searchResult : searchResults) {
            model.addElement(searchResult);
        }
    }

    menusList.setModel(model);
    this.jScrollPane1.repaint();
    return searchResults;
}

0 个答案:

没有答案