2016-06-20 129 views
-1

我试图使用从数据库表中抓取的名称创建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 
} 

任何帮助都会很棒。

回答

0

会这样的工作?

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

另外,我强烈建议改变Listlist

+0

这工作!谢谢! –