如何在Java Swing中的jtable中按数据显示分组? [英] How to display group by data in jtable in java swing?

查看:107
本文介绍了如何在Java Swing中的jtable中按数据显示分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在GroupWise中显示数据,如图所示,java swing jtable中有这种类型的字段.

I want to display data in GroupWise, there are this type of field in java swing jtable as shown in picture.

该怎么做?

推荐答案

首先,您应该创建一个Map<String,java.util.List<Product>> categuryProductMap = new HashMap<String, List<Product>>();.第一个论点 引用您的categuryName,第二个参数是 产品名称在相应类别中.

First You should create a Map<String,java.util.List<Product>> categuryProductMap = new HashMap<String, List<Product>>();. the first argument refers to your categuryName and the second argument is a list of product name in coresponding categury.

然后使用for语句先将类别添加,然后将产品列表添加到表模型中:

Then With for statement add first the categury then the list of product to your table model:

for (Map.Entry<String, java.util.List<Product>> entry : categuryProductMap.entrySet()) {
    String yourCateguryName = entry.getKey();
    tableModel.addRow(new Object[]{"", "", yourCateguryName, "", "", ""});
    for (Product productNameList : entry.getValue()) {
        String yourProductName = Product.getName();
        Object[] rowForProductName = new Object[]{"", "", yourProductName, "", "", ""};
        tableModel.addRow(rowForProductName);
    }
}

我希望这可以有所帮助.

i hope this can help little bit.

这篇关于如何在Java Swing中的jtable中按数据显示分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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