当前位置: 代码迷 >> Java相关 >> 求助:关于图形用户界面设计
  详细解决方案

求助:关于图形用户界面设计

热度:283   发布时间:2007-04-02 12:47:37.0
求助:关于图形用户界面设计
    我声明了一个JComboBox box = new JComboBox()和String str = {"黄","红","绿","紫","黑"},在声明的时候没有把str加入box里,而想在后面的程序中把str加入到box里,该怎么处理?
搜索更多相关的解决方案: 图形  用户界面  设计  

----------------解决方案--------------------------------------------------------

addItem

public void addItem(Object anObject)
Adds an item to the item list. This method works only if the JComboBox uses a mutable data model.

Warning: Focus and keyboard navigation problems may arise if you add duplicate String objects. A workaround is to add new objects instead of String objects and make sure that the toString() method is defined. For example:

   comboBox.addItem(makeObj("Item 1"));
   comboBox.addItem(makeObj("Item 1"));
   ...
   private Object makeObj(final String item)  {
     return new Object() { public String toString() { return item; } };
   }
 

Parameters:
anObject - the Object to add to the list


----------------解决方案--------------------------------------------------------
而且String str = {"黄","红","绿","紫","黑"},
是错误滴

[此贴子已经被作者于2007-4-2 13:15:26编辑过]


----------------解决方案--------------------------------------------------------