Get all selected checkboxes in Java

后端 未结 2 792
半阙折子戏
半阙折子戏 2021-01-13 08:50

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

2条回答
  •  一向
    一向 (楼主)
    2021-01-13 09:25

    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.

提交回复
热议问题