JCheckbox - ActionListener和ItemListener? [英] JCheckbox - ActionListener and ItemListener?

查看:199
本文介绍了JCheckbox - ActionListener和ItemListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ActionListener和ItemListener都用于使用JCheckBox触发事件?

Both ActionListener and ItemListener are used to fire an event with JCheckBox?

那么,它们之间的区别是什么?在这种情况下,其中一个优先于另一个?

So, what's the difference between them and in which case one of them is preferred to the other?

推荐答案

ItemListener 以及 ActionListener ,如果 JCheckBox 具有相同的行为。
但是,主要区别是 ItemListener 可以通过在复选框上调用 setSelected(true)来触发。
作为编码惯例,不要同时使用 ItemListener 以及 ActionListener > JCheckBox ,以避免不一致。

Both ItemListener as well as ActionListener, in case of JCheckBox have the same behaviour. However, major difference is ItemListener can be triggered by calling the setSelected(true) on the checkbox. As a coding practice do not register both ItemListener as well as ActionListener with the JCheckBox, in order to avoid inconsistency.

这篇关于JCheckbox - ActionListener和ItemListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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