核心Swing组件(五)
4.5 AbstractionButton类
如图4-1所示,AbstractButton类是作用在幕后作为所用 的Swing按钮组件的一个重要Swing类。在本章稍后的JButton类中所描述的JButton是最简单的子类。其余的子类将会在后续的章节中进行描述。
所有的AbstractButton子类使用ButtonModel接口来存储数据模型。DefaultButtonModel类是所使用的默认实现。另外,我们可以将任意的AbstractButton对象组合为一个ButtonGroup。尽管这种组合对于JRadioButton与JRadioButtonMenuItem组件最为自然,然而任意的AbstractButton子类都会起作用。
4.5.1 AbstractButton属性
表4-11列出了AbstractButton子类所共享的32个属性。这些属性可以使得我们自定义所有按钮的外观。
属性名 | 数据类型 | 访问性 |
action | Action | 读写绑定 |
actionCommand | String | 读写 |
actionListeners | ActionListener[] | 只读 |
borderPainted | boolean | 读写绑定 |
changeListeners | ChangeListener[] | 只读 |
contentAreaFilled | boolean | 读写绑定 |
disabledIcon | Icon | 读写绑定 |
disabledSelectedIcon | Icon | 读写绑定 |
disabledMnemonicIndex | int | 读写绑定 |
enabled | boolean | 只写 |
focusPainted | boolean | 读写绑定 |
horizontalAlignment | int | 读写绑定 |
horizontalTextPosition | int | 读写绑定 |
icon | Icon | 读写绑定 |
iconTextGap | int | 读写绑定 |
itemListeners | ItemListener[] | 只读 |
layout | LayoutManager | 只写 |
margin | Insets | 读写绑定 |
mnemonic | char | 读写绑定 |
mnemonic | int | 只写 |
model | ButtonModel | 读写绑定 |
multiClickThreshhold | long | 读写 |
pressedIcon | Icon | 读写绑定 |
rolloverEnabled | boolean | 读写绑定 |
rolloverIcon | Icon | 读写绑定 |
rolloverSelectedIcon | Icon | 读写绑定 |
selected | boolean | 读写 |
selectedIcon | Icon | 读写绑定 |
selectedObjects | Object[] | 只读 |
text | String | 读写绑定 |
UI | ButtonUI | 读写 |
verticalAlignment | int | 读写绑定 |
verticalTextPosition | int | 读写绑定 |
在这里值得一提的就是multiClickThreshhold。这个属性表示以毫秒计数的时间。如果一个按钮在这段时间间隔被鼠标多次选中,并不会产生额外的动作事件。默认情况下这个属性值为0,意味着每一次点击都会产生一个事件。为了避免在重要的对话框中偶然重复提交动作的发生,应将这个属性值设置0以上的合理值。
ButtonModel/Class DefaultButtonModel接口
ButtonModel接口被用来描述AbstractButton组件的当前状态。另外,他描述了为所有不同的AbstractButton子类所支持的事件监听器对象的集合。其定义如下:
public interface ButtonModel extends ItemSelectable { // Properties public String getActionCommand(); public void setActionCommand(String newValue); public boolean isArmed(); public void setArmed(boolean newValue); public boolean isEnabled(); public void setEnabled(boolean newValue); public void setGroup(ButtonGroup newValue); public int getMnemonic(); public void setMnemonic(int newValue); public boolean isPressed(); public void setPressed(boolean newValue); public boolean isRollover(); public void setRollover(boolean newValue); public boolean isSelected(); public void setSelected(boolean newValue); // Listeners public void addActionListener(ActionListener listener);
补充:软件开发 , Java ,
上一个:核心Swing组件(六)
下一个:中文数字转换成阿拉伯数字
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- SSH 导入导出excel 谁有这块的资料吗?
- springmvc 加载一个jsp页面执行多个方法 报404
- 关于用jquery 导入 excel
- java对时间进行循环放到List中
- 一个图片的输入输出程序,第一次调用某方法会中断,第二次调用则正常
- 请上过传智播客的人说一下传智播客怎么样呀!是不是像它说的那样好呀!
- spring的schema怎么配置
- 【菜鸟求助】SSH中怎么从JSP页面往后台传值呢