如何在jtable行中插入多个值的jcombobox [英] How to insert a jcombobox in a jtable row for multiple values

查看:99
本文介绍了如何在jtable行中插入多个值的jcombobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hashmap包含键和值(解析XML的结果)。 Hashmap包含的方式是key是一个字符串,value是一个向量。
键在向量中可以具有单个值,也可以在向量中具有多个值。
这个hashmap,必须放到一个jtable中,这样如果键有单个值,把它放到文本框。如果它有多个值,则在表中插入一个组合框。

Hashmap contains key and value(result of parsing an XML). Hashmap contains things in the way that key is a string and value is a vector. A key may have single value in the vector or mutiple values in the vector. This hashmap, has to be put into a jtable,such that if the key has single value, put it to text box. If it has multiple values insert a combobox in the table.

您可以更改代码。

hashmap.put(nodeList.item(j).getNodeName(), nodeValueList);
Set keys = PropertyIMPL.hashmap.keySet();
Iterator iteratorKeys = keys.iterator();

while (iteratorKeys.hasNext()) {
    String key = (String) iteratorKeys.next();
    if (nodeValueList.size() > 1) {
        tablemodel.insertRow(0, new Object[]{key});
        String[] ss = (String[]) nodeValueList.toArray(
            new String[nodeValueList.size()]);
        TableColumn col = table.getColumnModel().getColumn(1);
        col.setCellEditor(new MyComboBoxEditor(ss));
    } else {
        tablemodel.insertRow(0, new Object[]{key, nodeValueList});
    }
}

keys.clear();


推荐答案

简短的答案是你需要重写getCellEditor。 ..)方法。

Short answer is you need to override the getCellEditor(...) method of JTable.

这篇关于如何在jtable行中插入多个值的jcombobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆