java JComboBox的使用

JComboBox的itemStateChanged每次执行两次解决方法

		String[] item = {"aaa","bbb","ccc","ddd"};
		JComboBox jcb = new JComboBox(item);
		jcb.addItemListener(new ItemListener(){

			@Override
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED)//需要加上这句,因为Change有DESELECTED和SELECTED两种情况
				System.out.println((String)e.getItem());
				
			}
			
		});

 

posted on 2009-03-08 01:01  fatkun  阅读(1972)  评论(0编辑  收藏  举报

导航