如何自定义渲染一个JRadioButton的? [英] How can I customize the render of JRadioButton?

查看:321
本文介绍了如何自定义渲染一个JRadioButton的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个JRadioButton子类中,我重写paintComponent方法,像这样:

I've created a JRadioButton subclass in which I override the paintComponent method like so:

@Override
protected void paintComponent(Graphics g) {
    g.drawImage(
        isSelected() ? 
           getCheckedImg() :
           getBasicImg()
    , 0, 0, this);
}

但似乎一旦按钮被绘制,这是它使用永远的形象。该isSelected测试似乎没有产生任何影响。是图形缓存或Java的东西吗?如何提供我的自定义一个JRadioButton与选定的和未选定的图像?我必须编写自定义的用户界面?

but it seems that once the button is drawn, that's the image it uses forever. The isSelected test doesn't seem to have any effect. Are the graphics cached or something by Java? How do I provide my custom JRadioButton with a selected and unselected image? Do I have to write a custom UI?

推荐答案

阅读API。有喜欢的方法:

Read the API. There are methods like:

setIcon()
setSelectedIcon()

等等,你可以使用的,而不是做风俗画。

among others that you can use instead of doing custom painting.

这篇关于如何自定义渲染一个JRadioButton的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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