分配可变数量的新对象

时间:2016-06-20 13:58:41

标签: java

我正在尝试使用从数据库表中获取的名称来创建JMenu,因此JMenu项的数量将是可变的。

public static JMenuBar drawMenuBar(){
    ArrayList List = grabSQLTableNames();
    JMenuBar menu = new JMenuBar();
        JMenu contracts = new JMenu("Contracts");
            //from here I am a bit stuck on how to add new JMenuItems to the Menu
}

任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

这样的事情会起作用吗?

for (int i = 0; i < List.size(); i++) {
    JMenuItem item = new JMenuItem(List.get(i));
    contracts.add(item);
}

此外,我强烈建议您将List更改为list

相关问题