根据复选框在哈希图中显示对象的值 [英] showing values of object in hashmap according to checkboxes

查看:107
本文介绍了根据复选框在哈希图中显示对象的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个哈希图,并且有示例HashMap< string,dog)>

现在这只狗有了名字,大小,年龄等字段.

我有几个复选框,用户将检查要显示的狗的字段.因此,如果选择了checkboxname,它将在哈希图中显示所有名称.

初学者有可能吗? btw,hashmap< string ... string =" is =" the =" name =" of =" dogs.=" as =" it =" mode ="hold">
Tha是我到目前为止所做的,但是我真的很困惑.

I have a hashmap, and it has example HashMap<string,dog)>

Now the dog has fields like name, size, age ...

I have a couple of check boxes and the user will check the fields to display of the dog. so if checkboxname is selected it will display all the names in the hashmap.

is it possible for starters? btw, hashmap<string... string="" is="" the="" name="" of="" dogs.="" as="" it="" mode="hold">
Tha''s what i did so far, but im really stuck.

JCheckBox cbName = new JCheckBox("Name ");
        JCheckBox cbtype = new JCheckBox("Type ");
        JCheckBox cbDistance = new JCheckBox("Distance ");
JTextArea txttextarea = new JTextArea();

        if (cbName.isSelected() == true) {
            for (int i = 0; i <= DataCollection.map.values().size(); i++) {
                txttextarea.add(DataCollection.map.values().contains())
                
            }
        }

推荐答案

不要让它成为火箭科学.

您知道狗的数量,因此知道要显示的值的数量.
因此,使您的GUI更加动态:

Don''t make it rocket science.

You know the number of dogs and therefor the number of values to be displayed.
So make your GUI dynamically out of that:

if (cbName.isSelected() == true) {
  foreach (Dog oDog: oDogs){
    if(null != oDog.getName()){
      JCheckBox oCheckbox = new JCheckBox(oDog.getName());
    }
  }
}


这篇关于根据复选框在哈希图中显示对象的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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