---
title: "EXT-GWT--ComboBox使用实例"
author: "panfugen"
date: "2009-08-19T23:32:29Z"
tags: ["EXT", "GWT"]
slug: "ext-gwt-combobox"
draft: false
lastmod: "2009-08-19T23:44:55Z"
id: 453232
url: "https://anzeinfo.iteye.com/blog/453232"
---

最近用EXT-GWT写了很多界面,遇到了些问题，现在抽时间把这些问题整理一下，以便忘记时可以参考。 首先来看看EXT-GWT中下拉列表ComboBox的使用:combobox的正确使用必须注意两点: 1：ComboBox中泛型指定为BaseModel(或其子类简单来说的具有get("\[color=red]value\[/color]")和set("\[color=red]value\[/color]",value)这两个方法)BaseModel 2：setDisplayField("\[color=red]value\[/color]") 方法中颜色相同的关键字必须相同。 使用实例 \[code="java"]ListStore merchantStore = new ListStore(); merchantStore.add(getMerchant()); ComboBox merchant = new ComboBox(); merchant.setFieldLabel("商户:"); merchant.setDisplayField("merchant"); merchant.setValue(getMerchant().get(0));//设置初始值 merchant.setStore(merchantStore); private List getMerchant() { /\** * 商户类型 \*/ List list = new ArrayList(); list = new ArrayList(); BaseModel bm = new BaseModel(); bm.set("merchant", "法文：箱子(百联店)"); bm.set("key", "1"); list.add(bm); bm = new BaseModel(); bm.set("merchant", "法文：箱子(人南店)"); bm.set("key", "2"); list.add(bm); bm = new BaseModel(); bm.set("merchant", "法文：箱子(银都店)"); bm.set("key", "3"); list.add(bm); bm = new BaseModel(); bm.set("merchant", "法文：箱子(香槟店)"); bm.set("key", "4"); list.add(bm); return list; }\[/code] 相同颜色必须一致。 简单说了下拉列表的使用注意事项后，再来说一说ComboBox的触发事件Events.Change \[code="java"]merchant.addListener(Events.Change, new Listener() { @SuppressWarnings("unchecked") public void handleEvent(ComponentEvent be) { ComboBox selectBox = (ComboBox) be.component; String value = selectBox.getValue().get("merchant"); /\** * 事件处理 \*/ if ("自定义时段".equals(value)) { } else { } } });\[/code]