Java Swing, Trying to replace boolean check-box in a JTable with an image-icon checkbox

前端 未结 3 1867
忘了有多久
忘了有多久 2021-01-22 08:26

So I have a JTable with check-boxes. I would like to have the check-boxes contain one image when they are \"checked\" and another image when they are \"unchecked\" (i.e., displa

3条回答
  •  醉梦人生
    2021-01-22 09:26

    You would have to use the

    isSelected
    

    Method to see if the box is checked or not and by that you can use a if statement and if it is checked you use

    checkBox.setIcon(myIcon);
    

    Note that u can also u an ItemListener for the task of knowing if the box is selected or not.

    Question answeared using following resources: http://www.roseindia.net/java/example/java/swing/CustomizedCheckBox.shtml

    How to check that a JCheckBox is checked?

提交回复
热议问题