JComBox下拉框使用对象封装,显示时指定显示对象中的某一属性
2014-05-06 09:32
429 查看
public class Item { private String id; private String name; public Item() { } public Item(String id, String name) { this.id = id; this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } // 重写toString方法,将内容显示在下拉框中 public String toString() { return getName(); }} public class JComboBoxModelTest extends JFrame { JComboBox jc = new JComboBox(); JLabel jl = new JLabel("请选择证件:"); public JComboBoxModelTest() { setTitle("在窗口中设置下拉列表框"); Item item = new Item(); item.setId("1");item.setName("aa"); jc.addItem(item); item = new Item(); item.setId("2");item.setName("bb"); jc.addItem(item); item = new Item(); item.setId("3");item.setName("cc"); //下拉框直接添加对象,显示时会直接调用Item的toString方法 jc.addItem(item); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(jl); cp.add(jc); setSize(new Dimension(160, 180)); setVisible(true); } public static void main(String[] args) { new JComboBoxModelTest(); }}
相关文章推荐
- 对dao层封装后可以实现根据某一条属性查找到相应的javabean对象
- FMDB封装,用OC方法存储model,不用写SQL语句。使用runtime获取对象属性
- struts2对一些属性的使用和对session封装对象类型采用jstl技术的遍历(配图解)
- js获取指定节点对象的样式属性的值的封装函数(兼容ie、Opera和符合w3c标准浏览器)
- 使用Devexpress 的gridControl 绑定List列表(元素对象包含List属性)的Master-Detail显示
- js获取指定节点对象的样式属性的值的封装函数(兼容ie、Opera和符合w3c标准浏览器)
- 如何使用beanUtils对象的方法来封装实体对象属性?
- struts2对一些属性的使用和对session封装对象类型采用jstl技术的遍历(配图解)
- 浅谈ListBox控件,将对象封装在listBox中,在ListBox中显示对象中某个属性,在ListBox中移除和移动信息
- thymeleaf中使用layui 的自动化表格显示对象的某一属性值(格式化输出)
- 在VB6中,使用ADO对象模型时,ADO对象、属性、方法不“无法显示帮助”的问题?
- java使用反射机制根据属性名获取object对象指定属性的值
- JS使用Date对象实时显示当前系统时间简单示例
- ###struts模型驱动(必须new)能够封装【对象类型属性的属性】.页面传参错误导致的问题:HTTP Status 500 - could not execute statement;
- 从对象创建 到构造函数以及原型对象(prototype的使用,属性的共享)
- 采用重写tostring方法使ComboBox显示对象属性
- XML解析之sax解析案例(二)使用sax解析把 xml文档封装成对象
- ajax 快速入门,ajax底层使用的五个步骤;XMLHttpRequest对象详解;XMLHttpRequest常用属性;XMLHttpRequest常用方法
- 将Html原码解析成IHTMLDocumet对象,然后使用DOMNode将html显示成一棵树
- javascript的json对象中属性名使用uuid