Chinaunix首页 | 论坛 | 博客
  • 博客访问: 115615
  • 博文数量: 29
  • 博客积分: 170
  • 博客等级: 入伍新兵
  • 技术积分: 302
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-04 13:48
个人简介

linux 爱好者,java爱好者

文章分类

全部博文(29)

文章存档

2023年(1)

2022年(2)

2020年(3)

2019年(1)

2018年(3)

2017年(8)

2016年(1)

2015年(4)

2014年(2)

2009年(1)

2008年(3)

我的朋友

分类: Java

2020-09-01 20:51:11

在jtable中添加JComboBox控件
新建JComboBox对象,从jtable中得到列对象TableColumn,给此列设置JComboBox

javax.swing.JComboBox cbox1 = new JComboBox();
    cbox1.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            itemChanged(e); // comboBox某项被选中
        }
    });
    TableColumn tc0 = this.jTable1.getColumnModel().getColumn(0);
    tc0.setCellEditor(new DefaultCellEditor(cbox1));
    DefaultComboBoxModel cbm =(DefaultComboBoxModel) cbox1.getModel();
    
    for (Map row:sheetPrice){
        Integer id = 1;
        String type = "type";
        cbm.addElement(new u_sheet(id,type));
        
    }

u_sheet 是一个子定义的class
class u_sheet{
    private Integer id;
    private String type;
    public u_sheet(Integer id, String type) {
            this.id = id;
            this.type = type;
        }

        @Override
        public String toString() {  // 这句重要
            return this.type;
        }
        
    }
阅读(1799) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~