标题:求助:关于图形用户界面设计
只看楼主
herendagao
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2006-5-3
结帖率:100%
 问题点数:0 回复次数:2 
求助:关于图形用户界面设计
    我声明了一个JComboBox box = new JComboBox()和String str = {"黄","红","绿","紫","黑"},在声明的时候没有把str加入box里,而想在后面的程序中把str加入到box里,该怎么处理?
搜索更多相关主题的帖子: 图形 用户界面 设计 
2007-04-02 12:47
Eastsun
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:32
帖 子:802
专家分:0
注 册:2006-12-14
得分:0 

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


My BlogClick Me
2007-04-02 13:13
Eastsun
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:32
帖 子:802
专家分:0
注 册:2006-12-14
得分:0 
而且String str = {"黄","红","绿","紫","黑"},
是错误滴

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


My BlogClick Me
2007-04-02 13:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-128630-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.974919 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved