获取Java中的所有选中的复选框 [英] Get all selected checkboxes in Java

查看:1062
本文介绍了获取Java中的所有选中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java对话框,向用户提供〜15个复选框。有没有办法立即获得所有复选框的名称?目前,我一个一个地看,如果他们被选中,这不是一个解决方案的想法。

I have a dialog in Java that presents ~ 15 checkboxes to the user. Is there a way to get the names of all the checked checkboxes at once? Currently, I'm looking one by one if they are selected, which isn't that fancy of a solution.

我在寻找类似在数组中获取所有选中的复选框,但在Java中

I'm looking for something similar to Getting all selected checkboxes in an array but then in Java

推荐答案

当您将复选框添加到对话框中时,还会在某种集合中保留引用。然后当你想看看哪些检查,你可以只是迭代收集和检查每个的状态。您可以通过调用getText获取该名称。

When you are adding your Checkboxes to your dialog also keep a reference in a Collection of some sort. Then when you want to see which are checked you can just Iterate over the collection and check the state of each of them. You can get the name by calling getText on it.

这篇关于获取Java中的所有选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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